//
//  AddCustomersViewController.m
//  EMMApp
//
//  Created by Mac on 16/12/14.
//  Copyright © 2016年 YiXun. All rights reserved.
//

#import "AddCustomersViewController.h"

/** ViewController
 *
 *  ViewController导入.h文件
 */
#import "AttentionHuxingViewController.h"
#import "GroupViewController.h"
#import "HousingViewController.h"
#import "PerfectInformationViewController.h"
#import "AddSubscriptionViewController.h"       //认购新增
#import "AddNewSignViewController.h"            //签约新增

/** Api
 *
 *  首页Api调用导入.h文件
 */
#import "AddCustomerApi.h"
#import "EditCustomerApi.h"
#import "GetDictionaryListApi.h"
#import "GetProvinceCityAreaApi.h"
#import "CheckCustomerPhoneApi.h"
#import "YTKBatchRequest.h"
#import "GetDictionaryListByProjectIdApi.h"
#import "CheckCustomerIntentionApi.h"
#import "checkPhoneNumberApi.h"
/** Cell
 *
 *  首页Cell导入.h文件
 */
#import "NewCustomersCell.h"
#import "AddSubscriptionCell.h"
#import "ToutistsHomeViewCell.h"
#import "TourKHXXCell.h"

#import "EMMTousristsModel.h"


@interface AddCustomersViewController ()<UITableViewDataSource,UITableViewDelegate,UITextFieldDelegate,UIPickerViewDelegate,UIPickerViewDataSource,UITextViewDelegate> {

    //需求信息必填项个数
    NSString *xuqiuXXString;
    //@"客户个人信息"
    NSString *gdTJString1;
    
    NSString *sName;
    NSString *sId;
    NSString *sqName;
    NSString *sqId;
    NSString *xName;
    NSString *xId;
    NSString *_isActual;
}

/**
 *  创建UITableView
 */
@property (nonatomic, strong) UITableView *customersTableView;

/**
 *  创建存对应的数据
 */
@property (nonatomic, strong) NSMutableDictionary *customersDict;

/**
 *  创建二级列表是否展开状态
 */
@property (nonatomic, strong) NSMutableArray *selectedArr;

/**
 *  创建分区个数数组
 */
@property (nonatomic, strong) NSMutableArray *titleDataArray;


/**
 1、获知途径
 */
@property (nonatomic, strong) NSMutableArray *hztjList;

/**
 2、客户性质
 */
@property (nonatomic, strong) NSMutableArray *khxzList;

/**
 3、置业动机
 */
@property (nonatomic, strong) NSMutableArray *zydjList;


/**
 4关注重点
 */
@property (nonatomic,strong) NSMutableArray *rqFocusList;

/**
 6、生活服务
 */
@property (nonatomic,strong) NSMutableArray *rqServicesList;

/**
 11、首次接触方式
 */
@property (nonatomic, strong) NSMutableArray *tcfsList;


/**
 19、从事行业
 */
@property (nonatomic, strong) NSMutableArray *cshyList;

/**
 *  分区0
 */
//左侧数组
@property (nonatomic, strong) NSMutableArray *fenquDataArr0;
@property (nonatomic, assign) NSInteger fenqu0_h7;
@property (nonatomic, assign) NSInteger fenqu0_h8;
@property (nonatomic, assign) NSInteger fenqu0_h9;
@property (nonatomic, assign) NSInteger fenqu0_h10;

//姓名输入框
@property (nonatomic, strong) UITextField *nameTextField;
//选择星级
@property (nonatomic, strong) UIButton *xjBtn;
//显示星级
@property (nonatomic, strong) UIImageView *xjImageView;
//判断星级
@property (nonatomic, assign) BOOL isXj;
//字段 - 姓名
@property (nonatomic, strong) NSString *nameString;
//字段 - 星级id
@property (nonatomic, strong) NSString *xjNumber;

//字段 - 性别
@property (nonatomic, strong) NSString *sexString;
//字段 - 性别id
@property (nonatomic, strong) NSString *sexNumber;

//手机号输入框
@property (nonatomic, strong) UITextField *phonTextField;
//字段 - 手机号
@property (nonatomic, strong) NSString *phonSting;

//字段 - 客户等级
@property (nonatomic, strong) NSString *djString;
//字段 - 客户等级id
@property (nonatomic, strong) NSString *djNumber;

//字段 - 客户性质
@property (nonatomic, strong) NSString *lyStrting;
//字段 - 客户性质id
@property (nonatomic, strong) NSString *lyNumber;

////字段 - 客户状态
@property (nonatomic, strong) NSString *ztString;
//字段 - 客户状态id
@property (nonatomic, strong) NSString *ztNumber;

//字段 - 客户获知途径
@property (nonatomic, strong) NSString *informedwayEnumName;
//字段 - 客户获知途径id
@property (nonatomic, strong) NSString *informedWay;

//字段 - 推荐人类别
@property (nonatomic, strong) NSString *recommendedCategoryEnumName;
//字段 - 推荐人类别Id
@property (nonatomic, strong) NSString *recommendedCategoryEnum;

//字段 - 推荐人姓名
@property (nonatomic, strong) NSString *recommendedName;
//推荐人姓名输入框
@property (nonatomic, strong) UITextField *recommendedNameTextField;

//字段 - 推荐人手机
@property (nonatomic, strong) NSString *recommendedMobile;
//推荐人手机输入框
@property (nonatomic, strong) UITextField *recommendedMobileTextField;

//字段 - 推荐人单位
@property (nonatomic, strong) NSString *recommendedUnit;
//推荐人单位输入框
@property (nonatomic, strong) UITextField *recommendedUnitTextField;

//字段 - 首次接触方式
@property (nonatomic, strong) NSString *scjcFSSting;
//字段 - 首次接触方式id
@property (nonatomic, strong) NSString *scjcNumber;

//字段 - 首次接触方式时间
@property (nonatomic, strong) NSString *scjcSJSting;

//首次接触方式沟通内容文本框
@property (nonatomic, strong) UITextView *gtTextField;

//首次接触方式沟通内容文本框
@property (nonatomic, strong) UITextView *gtTextField1;


@property (nonatomic, assign) CGFloat gtTextFieldHeight;
@property (nonatomic, assign) CGFloat gtTextFieldHeight1;
//字段 - 首次接触方式内容
@property (nonatomic, strong) NSString *scGTSting;
@property (nonatomic, copy) NSString *scGTString1;

/**
 *  分区1 - 需求信息
 */
//左侧数组
@property (nonatomic, strong) NSMutableArray *fenquDataArr1;

//row = 1  - 关注重点
@property (nonatomic, assign) NSInteger fenqu1_h1;
//row = 9  - 意向房源
@property (nonatomic, assign) NSInteger fenqu1_h4;
//row = 10 - 生活服务
@property (nonatomic, assign) NSInteger fenqu1_h5;
//字段 - 置业动机
@property (nonatomic, strong) NSString *zyjdString;
//字段 - 置业动机id
@property (nonatomic, strong) NSString *zyjdNumber;
//字段 - 需求面积大小
@property (nonatomic, strong) NSString *xqmjString;       //面积
//字段 - 需求面积大小id
@property (nonatomic, strong) NSString *xqmjNumber;       //面积
//字段 - 付款方式
@property (nonatomic, strong) NSString *fkfsString;
//字段 - 付款方式id
@property (nonatomic, strong) NSString *fkfsNumber;
//字段 - 生活服务
@property (nonatomic, strong) NSString *fwSting;
//字段 - 生活服务id
@property (nonatomic, strong) NSString *fwNumber;
//字段 - 意向房源数组
@property (nonatomic, strong) NSMutableArray *housingArr;
//字段 - 意向房源数组id
@property (nonatomic, strong) NSMutableArray *housingArrId;
//字段 - 关注重点名称
@property (nonatomic, strong) NSMutableArray *gzzdArr;
//字段 - 关注重点id数组
@property (nonatomic, strong) NSMutableArray *gzzdIdArr;
//字段 - 关注重点id
@property (nonatomic, strong) NSString *gzzdNumber;


/**
 *  分区3 - 客户个人信息
 */
//左侧数组
@property (nonatomic, strong) NSMutableArray *fenquDataArr3;
//字段 - 居住区
@property (nonatomic, strong) NSString *khJZQSting;
//字段 - 居住区县Id
@property (nonatomic, strong) NSString<Optional> *peResidenceAreaId;
//字段 - 居住区市Id
@property (nonatomic, strong) NSString<Optional> *peResidenceCityId;
//字段 - 居住区省Id
@property (nonatomic, strong) NSString<Optional> *peResidenceProvinceId;

//字段 - 工作区
@property (nonatomic, strong) NSString<Optional> *peWorkaround;
//c字段 - 工作区省Id
@property (nonatomic, strong) NSString<Optional> *peWorkaroundProvinceId;
//字段 - 工作区市Id
@property (nonatomic, strong) NSString<Optional> *peWorkaroundCityId;
//字段 - 工作区县Id
@property (nonatomic, strong) NSString<Optional> *peWorkaroundAreaId;
//字段 - 工作区选择
@property (nonatomic, strong) NSString *khGZQSting;
//字段 - 客户从事行业
@property (nonatomic, strong) NSString *khCszyString;
//字段 - 客户从事行业id
@property (nonatomic, strong) NSString *khCszyIdString;
/**
 *  创建选择省市区
 */
@property (nonatomic, strong) NSMutableArray *levelOneArr;
@property (nonatomic, assign) NSInteger levelOneSelect;

@property (nonatomic, strong) NSMutableArray *levelTwoArr;
@property (nonatomic, assign) NSInteger levelTwoSelect;

@property (nonatomic, strong) NSMutableArray *levelThrArr;
@property (nonatomic, assign) NSInteger levelThrSelect;

@property (nonatomic, strong) UIPickerView *pickerView;

@property (nonatomic, strong) UIView *sHQPickerView;

@property (nonatomic, strong) UIView *sHQSeleView;

@property (nonatomic, strong) NSString *qbSsqString;

//更新5个本地

//【生活服务】-rqServices、的名字数组与id数组
@property (nonatomic, strong) NSMutableArray *rqServicesNameArr;
@property (nonatomic, strong) NSMutableArray *rqServicesIdArr;

//【生活配套】- rqLifeSupport、的名字数组与id数组
@property (nonatomic, strong) NSMutableArray *rqLifeSupportNameArr;
@property (nonatomic, strong) NSMutableArray *rqLifeSupportIdArr;

//【乐于参加的活动类型】- peActivityType、的名字数组与id数组
@property (nonatomic, strong) NSMutableArray *peActivityTypeNameArr;
@property (nonatomic, strong) NSMutableArray *peActivityTypeIdArr;

//【兴趣爱好】- peHobbyId、的名字数组与id数组
@property (nonatomic, strong) NSMutableArray *peHobbyNameArr;
@property (nonatomic, strong) NSMutableArray *peHobbyIdArr;

//【日常信息获取途径】- dailyInformation、的名字数组与id数组
@property (nonatomic, strong) NSMutableArray *dailyInformationNameArr;
@property (nonatomic, strong) NSMutableArray *dailyInformationIdArr;

@end

@implementation AddCustomersViewController

#pragma mark - 初始化
- (void)viewDidLoad {
    [super viewDidLoad];
    _gzzdArr = [[NSMutableArray alloc] init];
    _gzzdIdArr = [[NSMutableArray alloc] init];
    
    _housingArr = [[NSMutableArray alloc] init];
    _housingArrId = [[NSMutableArray alloc] init];
    
    _rqServicesNameArr = [[NSMutableArray alloc] init];
    _rqServicesIdArr = [[NSMutableArray alloc] init];
    
    _rqLifeSupportNameArr = [[NSMutableArray alloc] init];
    _rqLifeSupportIdArr = [[NSMutableArray alloc] init];
    
    _peActivityTypeNameArr = [[NSMutableArray alloc] init];
    _peActivityTypeIdArr = [[NSMutableArray alloc] init];
    
    _peHobbyNameArr = [[NSMutableArray alloc] init];
    _peHobbyIdArr = [[NSMutableArray alloc] init];
    
    _dailyInformationNameArr = [[NSMutableArray alloc] init];
    _dailyInformationIdArr = [[NSMutableArray alloc] init];
    
    
//    [self creatNavigationController];
    
    _customersTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH,EMM_HEIGHT-65-SafeAreaTopHeight-10) style:UITableViewStylePlain];
    _customersTableView.delegate = self;
    _customersTableView.dataSource = self;
    _customersTableView.showsVerticalScrollIndicator = NO;
    //不要分割线
    _customersTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:_customersTableView];
    
    [self initDataSource];
    [self creatinitWithButton];
    //省市区Api调用
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    NSString *str = [userdf objectForKey:@"provinceCityDistrict"];
    if ([NSString isStringEmpty2:str] == YES) {
        [self postGetProvinceCityAreaApiParentId:nil];
    }else {
        [self creatCity];
    }
    [self creatHQDictInitWith];
    //返回按钮初始化
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setFrame:CGRectMake(0, 0, 54 ,44)];
    [backBtn addTarget:self
                action:@selector(NewbackToPreviousPage:)
      forControlEvents:UIControlEventTouchUpInside];
    [backBtn setBackgroundColor:[UIColor clearColor]];
    [backBtn setImage:[UIImage imageNamed:@"ico_back"] forState:UIControlStateNormal];
    backBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    if (EMM_WIDTH <= 320) {
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }else if (EMM_WIDTH > 375){
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    }else{
        backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 0);
    }
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
    
    if (!self.isflg) {
        [self getNowData];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - 返回按钮调用方法
- (void)NewbackToPreviousPage:(id) send {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"您的信息尚未保存，是否确认放弃？" preferredStyle:UIAlertControllerStyleAlert];
 
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        [self NewCreatUpExit];//退出
    }];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    }];

    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)NewCreatUpExit {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 左侧数据初始化
-(void)initDataSource {
    //分区个数
    _titleDataArray = [[NSMutableArray alloc] initWithObjects:
                       @"0",@"需求信息",@"客户个人信息",nil];
    //第0分区
    _fenquDataArr0 = [[NSMutableArray alloc] initWithObjects:
                      @"客户姓名",@"性别",@"联系电话",@"意向等级",
                      @"获知途径",@"推荐人类别",
                      @"推荐人姓名",@"推荐人手机号",@"推荐人单位",
                      nil];
    
    if (self.getCustomerDetail.ftContactTime && self.getCustomerDetail.ftContactWay) {
        [_fenquDataArr0 addObject:@"首次接触方式"];
        [_fenquDataArr0 addObject:@"首次接触时间"];
        [_fenquDataArr0 addObject:@"沟通内容"];
    }
    if (self.getCustomerDetail.ftContactTime1 && self.getCustomerDetail.ftContactWay1) {
        [_fenquDataArr0 addObject:@"首次接触方式"];
        [_fenquDataArr0 addObject:@"首次接触时间"];
        [_fenquDataArr0 addObject:@"沟通内容"];
    }
    if (!self.isflg) {
        [_fenquDataArr0 addObject:@"首次接触方式"];
        [_fenquDataArr0 addObject:@"首次接触时间"];
        [_fenquDataArr0 addObject:@"沟通内容"];
    }
    
    if ([_informedwayEnumName isEqualToString:@"外部推荐"] ||[_informedwayEnumName isEqualToString:@"全员营销"] ) {
        _fenqu0_h7 = 50;
        _fenqu0_h8 = 50;
        _fenqu0_h9 = 50;
        _fenqu0_h10 = 50;
    } else {
        _fenqu0_h7 = 0;
        _fenqu0_h8 = 0;
        _fenqu0_h9 = 0;
        _fenqu0_h10 = 0;
    }
    //第1分区
    _fenquDataArr1 = [[NSMutableArray alloc]initWithObjects:
                      @"置业动机",@"关注重点",@"需求面积",@"付款方式",@"生活服务",nil];
    _fenqu1_h1 = 50;
    _fenqu1_h4 = 50;
    _fenqu1_h5 = 50;

    //第2分区
    _fenquDataArr3 = [[NSMutableArray alloc] initWithObjects:@"居住区",@"工作区",@"从事行业",nil];
}

#pragma mark - 获取当前时间
- (void)getNowData {
    NSString *path = [NSString stringWithFormat:@"%@/appapi/getServerTime", apiBaseUrl];
    [[AFHTTPSessionManager manager]GET:path parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) {
        NSDictionary *dict = responseObject[@"resData"];
        NSString *date = dict[@"serverTime"];
        if (date.length > 11) {
            NSString *today = [date substringToIndex:10];
            self.scjcSJSting = [NSString stringWithFormat:@"%@", today];
        }
        [self.customersTableView reloadData];
    } failure:^(NSURLSessionDataTask *task, NSError *error) {
        
    }];
    
}


#pragma mark - 客户数据api调用方法
#pragma mark - 省市区
- (void)postGetProvinceCityAreaApiParentId:(NSString *)parentId {
    GetProvinceCityAreaApi *api = [[GetProvinceCityAreaApi alloc] initWithParentId:nil];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetProvinceCityAreaApi *result = (GetProvinceCityAreaApi *)request;
        if (result.isSuccess) {
            GetProvinceCityArea *get = result.resultData;
            NSData *data = [get.provinceCityAreaList dataUsingEncoding:NSUTF8StringEncoding];
            NSArray *arr = (NSArray *)[data mutableObjectFromJSONData];
            NSMutableArray *oneArr = [[NSMutableArray alloc] init];
            NSMutableArray *twoArr = [[NSMutableArray alloc] init];
            NSMutableArray *thrArr = [[NSMutableArray alloc] init];
            for (NSDictionary *dict in arr) {
                //省、直辖市、自治区ID
                NSString *provinceId = [dict objectForKey:@"provinceId"];
                //省、直辖市、自治区名称
                NSString *province = [dict objectForKey:@"province"];
                
                NSDictionary *oneDict = [NSDictionary dictionaryWithObjectsAndKeys:provinceId,@"provinceId",province,@"province", nil];
                [oneArr addObject:oneDict];
                //
                NSMutableArray *subTwoArr = [[NSMutableArray alloc] init];
                for (NSDictionary *cityDict in dict[@"cities"]) {
                    //市ID
                    NSString *cityId = [cityDict objectForKey:@"cityId"];
                    //市名称
                    NSString *city = [cityDict objectForKey:@"city"];
                    
                    NSDictionary *subTwoDict = [NSDictionary dictionaryWithObjectsAndKeys:cityId,@"cityId",city,@"city", nil];
                    [subTwoArr addObject:subTwoDict];
                    //
                    NSMutableArray *subThrArr = [[NSMutableArray alloc] init];
                    for (NSDictionary *distDict in cityDict[@"districts"]) {
                        //县、旗、区ID
                        NSString *districtId = [distDict objectForKey:@"districtId"];
                        //县、旗、区名称
                        NSString *district = [distDict objectForKey:@"district"];
                        
                        NSDictionary *subThrDict = [NSDictionary dictionaryWithObjectsAndKeys:districtId,@"districtId",district,@"district", nil];
                        [subThrArr addObject:subThrDict];
                    }
                    //
                    NSDictionary *thrDict = [NSDictionary dictionaryWithObjectsAndKeys:subThrArr,cityId, nil];
                    [thrArr addObject:thrDict];
                }
                //
                NSDictionary *twoDict = [NSDictionary dictionaryWithObjectsAndKeys:subTwoArr,provinceId, nil];
                [twoArr addObject:twoDict];
            }
            self.levelOneArr = [NSMutableArray arrayWithArray:oneArr];
            self.levelTwoArr = [NSMutableArray arrayWithArray:twoArr];
            self.levelThrArr = [NSMutableArray arrayWithArray:thrArr];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            [userdf setObject:get.provinceCityAreaList forKey:@"provinceCityDistrict"];
            [userdf synchronize];
            [self creatCity];
            //            [self sHQPickerShowUI];
        } else {
            [self showToast:result.resultData.errorMsg];
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark - 获取省市区

- (void)creatCity {
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    NSString *str = [userdf objectForKey:@"provinceCityDistrict"];
    NSData *data = [str dataUsingEncoding:NSUTF8StringEncoding];
    NSArray *arr = (NSArray *)[data mutableObjectFromJSONData];
    NSMutableArray *oneArr = [[NSMutableArray alloc] init];
    NSMutableArray *twoArr = [[NSMutableArray alloc] init];
    NSMutableArray *thrArr = [[NSMutableArray alloc] init];
    for (NSDictionary *dict in arr) {
        //省、直辖市、自治区ID
        NSString *provinceId = [dict objectForKey:@"provinceId"];
        //省、直辖市、自治区名称
        NSString *province = [dict objectForKey:@"province"];
        NSDictionary *oneDict = [NSDictionary dictionaryWithObjectsAndKeys:provinceId,@"provinceId",province,@"province", nil];
        [oneArr addObject:oneDict];
        //
        NSMutableArray *subTwoArr = [[NSMutableArray alloc] init];
        for (NSDictionary *cityDict in dict[@"cities"]) {
            //市ID
            NSString *cityId = [cityDict objectForKey:@"cityId"];
            //市名称
            NSString *city = [cityDict objectForKey:@"city"];
            
            NSDictionary *subTwoDict = [NSDictionary dictionaryWithObjectsAndKeys:cityId,@"cityId",city,@"city", nil];
            [subTwoArr addObject:subTwoDict];
            //
            NSMutableArray *subThrArr = [[NSMutableArray alloc] init];
            for (NSDictionary *distDict in cityDict[@"districts"]) {
                //县、旗、区ID
                NSString *districtId = [distDict objectForKey:@"districtId"];
                //县、旗、区名称
                NSString *district = [distDict objectForKey:@"district"];
                
                NSDictionary *subThrDict = [NSDictionary dictionaryWithObjectsAndKeys:districtId,@"districtId",district,@"district", nil];
                [subThrArr addObject:subThrDict];
            }
            //
            NSDictionary *thrDict = [NSDictionary dictionaryWithObjectsAndKeys:subThrArr,cityId, nil];
            [thrArr addObject:thrDict];
        }
        //
        NSDictionary *twoDict = [NSDictionary dictionaryWithObjectsAndKeys:subTwoArr,provinceId, nil];
        [twoArr addObject:twoDict];
    }
    self.levelOneArr = [NSMutableArray arrayWithArray:oneArr];
    self.levelTwoArr = [NSMutableArray arrayWithArray:twoArr];
    self.levelThrArr = [NSMutableArray arrayWithArray:thrArr];
    [self sHQPickerShowUI];
}

#pragma mark - 获取字典
- (void)creatHQDictInitWith {
    //获取客户字典 的数组初始化
    //1、获知途径
    _hztjList = [[NSMutableArray alloc] init];
    
    //2、客户性质
    _khxzList = [[NSMutableArray alloc] init];
    
    //3、置业动机
    _zydjList = [[NSMutableArray alloc] init];
    
    //4关注重点
    _rqFocusList = [[NSMutableArray alloc] init];
    
    // 6、生活服务
    _rqServicesList = [[NSMutableArray alloc] init];
    
    //11、首次接触方式
    _tcfsList = [[NSMutableArray alloc] init];
    
    //19、从事行业
    _cshyList = [[NSMutableArray alloc] init];
    
    [self postGetDictionaryListByProjectIdApi];
}


- (void)postGetDictionaryListByProjectIdApi {
    
    GetDictionaryListByProjectIdApi *api = [[GetDictionaryListByProjectIdApi alloc] initWithBusNum:@"01"];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        GetDictionaryListByProjectIdApi *result = (GetDictionaryListByProjectIdApi *)request;
        if (result.isSuccess) {
            GetDictionaryListByProjectId *get = result.resultData;

            //1、获知途径
            _hztjList = [get.typeMap objectForKey:@"informedWay"];
            
            //2、客户性质
            _khxzList = [get.typeMap objectForKey:@"customerNature"];
            
            //3、置业动机
            _zydjList = [get.typeMap objectForKey:@"theirMotives"];
            
            //4关注重点
            _rqFocusList = [get.typeMap objectForKey:@"focus"];
            
            // 6、生活服务
            _rqServicesList = [get.typeMap objectForKey:@"lifeService"];
            
            //11、首次接触方式
            _tcfsList = [get.typeMap objectForKey:@"contactWay"];
            
            //19、从事行业
            _cshyList = [get.typeMap objectForKey:@"congshihangye"];

        } else {
            [self showToast:result.resultData.errorMsg];
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self creatNavigationController];
        [self hideHud];
        [_customersTableView reloadData];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
        [self creatNavigationController];
        [_customersTableView reloadData];
    }];
}

#pragma mark - 检查手机号是否重复
- (void)CheckCustomerPhoneApiPhone:(NSString *)phone peMobile:(NSString *)peMobile isDistinguish:(NSString *)isDistinguish {
    NSString *opone;
    if (_isflg == YES) {
        opone = @"2";
    } else {
        opone = @"1";
    }
    CheckCustomerPhoneApi *api = [[CheckCustomerPhoneApi alloc] initWithCustomerPhone:phone
                                                                             operType:opone
                                                                           customerId:self.customerId
                                                                             peMobile:peMobile];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        CheckCustomerPhoneApi *result = (CheckCustomerPhoneApi *)request;
        if (result.isSuccess) {
            CheckCustomerPhone *check = result.resultData;
            if ([check.result isEqualToString:@"1"]) {
                if ([NSString isStringEmpty:result.resultData.errorMsg] == NO) {
                    [self showToast:result.resultData.errorMsg];
                    if ([isDistinguish isEqualToString:@"1"]) {
                        _phonSting = nil;
                    }
                }
            }
        } else {
//            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                [appInstance showLogin];
                
            } else if ( [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
            
            if ([isDistinguish isEqualToString:@"1"]) {
                _phonSting = nil;
            }
        }
        [_customersTableView reloadData];
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark - 导航
- (void)creatNavigationController {
    [self updateNavBar];
    if (_isflg == NO) {
        self.navigationItem.title = @"新增客户";
        _xjNumber = @"0";
        _djString = @"D";
        _djNumber = @"5";
        xuqiuXXString = @"0";
        gdTJString1 = @"0";
//        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
//        NSDate * date = [NSDate date];//当前时间
        if (self.isflg) {
            _scjcSJSting = self.getCustomerDetail.ftContactTime ? self.getCustomerDetail.ftContactTime : self.getCustomerDetail.ftContactTime1;//[dateFormatter stringFromDate:date];
        }
        _selectedArr = [[NSMutableArray alloc] initWithObjects:@"0",@"1",@"2", nil];
        UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(100, 5, EMM_WIDTH - 100, 50)];
        textView.font = [UIFont systemFontOfSize:15];
        textView.text = _scGTSting;
        _gtTextFieldHeight = [self heightForString:textView andWidth:EMM_WIDTH - 100];
        
        UITextView *textView1 = [[UITextView alloc] initWithFrame:CGRectMake(100, 5, EMM_WIDTH - 100, 50)];
        textView1.font = [UIFont systemFontOfSize:15];
        textView1.text = self.scGTString1;
        _gtTextFieldHeight1 = [self heightForString:textView1 andWidth:EMM_WIDTH - 100];
        
    }else {
        self.navigationItem.title = @"编辑客户";
        [self creatInitWithEidtShowUI];
    }
}

#pragma mark - 修改客户信息
- (void)creatInitWithEidtShowUI {
    _nameString = _getCustomerDetail.customerName;
    _sexString = _getCustomerDetail.customerSex;
    if ([_sexString isEqualToString:@"男"]) {
        _sexNumber = @"1";
    }else {
        _sexNumber = @"2";
    }

    if ([_getCustomerDetail.customerStar isEqualToString:@"否"]) {
        _xjNumber = @"0";
        _isXj = NO;
    }else {
        _xjNumber = @"1";
        _isXj = YES;
    }
    _phonSting = _getCustomerDetail.customerPhone;
  
    if ([_isTransaction isEqualToString:@"1"]) {
        _djString = @"A";
        _djNumber = @"2";
    }else {
        _djString = _getCustomerDetail.intentionLevel;
        NSArray *djArr = [NSArray arrayWithObjects:@"A",@"B",@"C",@"D", nil];
        for (int i = 0; i < djArr.count; i++) {
            NSString *str = [djArr objectAtIndex:i];
            if ([_djString isEqualToString:str]) {
                _djNumber = [NSString stringWithFormat:@"%d",i+2];
            }
        }
    }
    
    if ([_djString isEqualToString:@"A"]) {//A
        gdTJString1 = @"3";
        xuqiuXXString = @"6";
    }else {
        //B,C,D必填项都相同
        gdTJString1 = @"0";
        xuqiuXXString = @"0";
    }
    _selectedArr = [[NSMutableArray alloc] initWithObjects:@"0",@"1",@"2", nil];

    _lyStrting = _getCustomerDetail.customerOrigin;
    for (int i = 0; i < _khxzList.count; i++) {
        NSMutableDictionary *dict = [_khxzList objectAtIndex:i];
        if ([_lyStrting isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
            _lyNumber = [dict objectForKey:@"dictionaryId"];
        }
    }
    _ztString = _getCustomerDetail.customerStatus;
    if ([_ztString isEqualToString:@"问询"]) {
        _ztNumber = @"1";
    }else if ([_ztString isEqualToString:@"来访"]) {
        _ztNumber = @"2";
    }else if ([_ztString isEqualToString:@"认筹"]) {
        _ztNumber = @"3";
    }else if ([_ztString isEqualToString:@"认购"]) {
        _ztNumber = @"4";
    }else if ([_ztString isEqualToString:@"签约"]) {
        _ztNumber = @"5";
    }else if ([_ztString isEqualToString:@"无意向"]) {
        _ztNumber = @"6";
    }
    
    //置业动机
    _zyjdString = _getCustomerDetail.rqTheirMotives;
    for (int i = 0; i < _zydjList.count; i++) {
        NSMutableDictionary *dict = [_zydjList objectAtIndex:i];
        if ([_zyjdString isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
            _zyjdNumber = [dict objectForKey:@"dictionaryId"];
        }
    }
    
    //关注重点
    
    for (CustomerFocusList *clist in _getCustomerDetail.customerFocusList) {
        if ([NSString isStringEmpty2:clist.focusName] == NO) {
            [_gzzdArr addObject:clist.focusName];
        }
        if ([NSString isStringEmpty2:clist.focusId] == NO) {
            [_gzzdIdArr addObject:clist.focusId];
        }
    }
    _gzzdNumber = [_gzzdIdArr componentsJoinedByString:@","];
    
    _fenqu1_h1 = 50+(int)_gzzdArr.count*50;

    _xqmjString = _getCustomerDetail.rqDemandArea;
    NSArray *xqmjArr = [NSArray arrayWithObjects:
                        @"50㎡以下",@"50-70㎡",@"70-90㎡",
                        @"90-120㎡", @"120-140㎡",@"140-160㎡",@"160-180㎡",@"180-200㎡",@"200㎡以上",nil];
    for (int i = 0; i < xqmjArr.count; i++) {
        NSString *str = [xqmjArr objectAtIndex:i];
        if ([_xqmjString isEqualToString:str]) {
            _xqmjNumber = [NSString stringWithFormat:@"%d",i+1];
        }
    }
    
    _fkfsString = _getCustomerDetail.rqPaymentMethod;
    NSArray *fkfsArr = [NSArray arrayWithObjects:
                        @"一次性付款",@"分期付款",@"商业按揭",
                        @"公积金按揭 ", @"组合贷款", nil];
    for (int i = 0; i < fkfsArr.count; i++) {
        NSString *str = [fkfsArr objectAtIndex:i];
        if ([_fkfsString isEqualToString:str]) {
            _fkfsNumber = [NSString stringWithFormat:@"%d",i+1];
        }
    }
  
    //意向房源housingArr
    NSMutableArray *roomArr = [[NSMutableArray alloc] init];
    NSMutableArray *roomArrId = [[NSMutableArray alloc] init];
    for (RoomList *rList in _getCustomerDetail.roomList) {
        NSString *strUrl = [rList.roomName stringByReplacingOccurrencesOfString:@"-->" withString:@"-"];
        [roomArr addObject:strUrl];
        [roomArrId addObject:@{@"roomId":rList.roomId}];
    }
    _housingArr = roomArr;
    _housingArrId = roomArrId;
    _fenqu1_h4 = 50+(int)_housingArr.count*50;
    
    
    //生活服务 - list

    for (CustomeServicesList *clist in _getCustomerDetail.customeServicesList) {
        if ([NSString isStringEmpty2:clist.servicesName] == NO) {
            [_rqServicesNameArr addObject:clist.servicesName];
        }
        if ([NSString isStringEmpty2:clist.servicesId] == NO) {
            [_rqServicesIdArr addObject:clist.servicesId];
        }
    }
    _fwNumber = [_rqServicesIdArr componentsJoinedByString:@","];
    
    _fenqu1_h5 = 50+(int)_rqServicesNameArr.count*50;
    
   
    //更多
    //1
    _scjcFSSting = _getCustomerDetail.ftContactWay ? _getCustomerDetail.ftContactWay : _getCustomerDetail.ftContactWay1;
    for (int i = 0; i < _tcfsList.count; i++) {
        NSMutableDictionary *dict = [_tcfsList objectAtIndex:i];
        if ([_scjcFSSting isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
            _scjcNumber = [dict objectForKey:@"dictionaryId"];
        }
    }
    
//    if ([NSString isStringEmpty2:_getCustomerDetail.ftContactTime] == YES) {
//        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//        [dateFormatter setDateFormat:@"yyyy-MM-dd"];
//        NSDate * date = [NSDate date];//当前时间
//        _scjcSJSting = [dateFormatter stringFromDate:date];
//    }else {
    if (self.isflg) {
        _scjcSJSting = _getCustomerDetail.ftContactTime ? _getCustomerDetail.ftContactTime :_getCustomerDetail.ftContactTime1;
    }
//    }
    
    _scGTSting = _getCustomerDetail.ftContactContent ? _getCustomerDetail.ftContactContent : _getCustomerDetail.ftContactContent1;
    self.scGTString1 = _getCustomerDetail.ftContactContent1;
    //计算textView的高度
    UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(100, 5, EMM_WIDTH - 100, 50)];
    textView.font = [UIFont systemFontOfSize:15];
    textView.text = _scGTSting;
    _gtTextFieldHeight = [self heightForString:textView andWidth:EMM_WIDTH - 100];
    
    //计算textView的高度
    UITextView *textView1 = [[UITextView alloc] initWithFrame:CGRectMake(100, 5, EMM_WIDTH - 100, 50)];
    textView1.font = [UIFont systemFontOfSize:15];
    textView1.text = self.scGTString1;
    _gtTextFieldHeight1 = [self heightForString:textView1 andWidth:EMM_WIDTH - 100];

    //从事行业
    _khCszyString = _getCustomerDetail.industry;
    for (int i = 0; i < _cshyList.count; i++) {
        NSMutableDictionary *dict = [_cshyList objectAtIndex:i];
        if ([_khCszyString isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
            _khCszyIdString = [dict objectForKey:@"dictionaryId"];
        }
    }
    
   
    _informedwayEnumName = _getCustomerDetail.informedWay;
    for (int i = 0; i < _hztjList.count; i++) {
        NSMutableDictionary *dict = [_hztjList objectAtIndex:i];
        if ([_informedwayEnumName isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
            _informedWay = [dict objectForKey:@"dictionaryId"];
        }
    }
    
    if ([_informedwayEnumName isEqualToString:@"外部推荐"] ||[_informedwayEnumName isEqualToString:@"全员营销"] ) {
        _fenqu0_h7 = 50;
        _fenqu0_h8 = 50;
        _fenqu0_h9 = 50;
        _fenqu0_h10 = 50;
    } else {
        _fenqu0_h7 = 0;
        _fenqu0_h8 = 0;
        _fenqu0_h9 = 0;
        _fenqu0_h10 = 0;
    }
    _recommendedCategoryEnumName = _getCustomerDetail.recommendedCategory;
    NSArray *aqrr = [NSArray arrayWithObjects:
                     @"分销/中介",@"老客户(未成交客户)",@"老业主",nil];
    for (int i = 0; i < aqrr.count; i++) {
        NSString *str = [aqrr objectAtIndex:i];
        if ([_recommendedCategoryEnumName isEqualToString:str]) {
            _recommendedCategoryEnum = [NSString stringWithFormat:@"%d",i+1];
        }
    }
    
    _recommendedName = _getCustomerDetail.recommendedName;
    _recommendedMobile = _getCustomerDetail.recommendedMobile;
    _recommendedUnit = _getCustomerDetail.recommendedUnit;
   
    
    _khJZQSting= _getCustomerDetail.peResidence;
    _peResidenceProvinceId = _getCustomerDetail.peResidenceProvinceId;
    _peResidenceCityId = _getCustomerDetail.peResidenceCityId;
    _peResidenceAreaId = _getCustomerDetail.peResidenceAreaId;
    
    _peWorkaroundProvinceId = _getCustomerDetail.peWorkaroundProvinceId;
    _peWorkaroundCityId = _getCustomerDetail.peWorkaroundCityId;
    _peWorkaroundAreaId= _getCustomerDetail.peWorkaroundAreaId;
    _khGZQSting= _getCustomerDetail.peWorkaround;

    [_customersTableView reloadData];
    
}

#pragma mark----tableViewDelegate
//返回几个表头
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _titleDataArray.count;
}

//每一个表头下返回几行
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if (section == 0) {
        //第0分区
        return _fenquDataArr0.count;
    } else if (section == 1) {
        if ([_selectedArr containsObject:string]) {
            return _fenquDataArr1.count;
        }
        return 0;
    }else if (section == 2) {
        if ([_selectedArr containsObject:string]) {
            return _fenquDataArr3.count;
        }
        return 0;
    }
    return 0;
}

//分区头设置表头的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0.1f;
    }
    return 50;
}

//分区尾视图高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 5;
}

//分区尾视图View
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 5)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

//分区透视图View
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 50)];
    view.backgroundColor = [UIColor colorFromHexCode:@"#fff5e9"];
    
    UILabel *sLabel6 = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 4, 30)];
    sLabel6.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    [view addSubview:sLabel6];
    
    UIImageView *upImageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-30, 20, 20, 10)];
    [view addSubview:upImageView];
    NSString *string = [NSString stringWithFormat:@"%ld",section];
    if ([_selectedArr containsObject:string]) {
        upImageView.image = [UIImage imageNamed:@"sanjt_down"];
    }else {
        upImageView.image = [UIImage imageNamed:@"sanjt_up"];
    }
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 15, tableView.frame.size.width-20, 20)];
    titleLabel.font = [UIFont systemFontOfSize:15];
    [view addSubview:titleLabel];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0, 0, EMM_WIDTH, 50);
    button.tag = 100+section;
    [button addTarget:self action:@selector(doButton:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:button];
    
    if (section == 0) {
        return nil;
    } else if (section == 1) {
        //需求信息
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@(%@项必填)",[_titleDataArray objectAtIndex:1],xuqiuXXString]];
        
        [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorFromHexCode:@"#1A1A1A"] range:NSMakeRange(0,4)];
        [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(4,str.length-4)];
        if (![xuqiuXXString isEqualToString:@"0"]) {
            if ([NSString isStringEmpty2:xuqiuXXString] == NO) {
                titleLabel.attributedText = str;
            }else {
                titleLabel.text = @"(项必填)";
            }
        }else {
            titleLabel.text = [_titleDataArray objectAtIndex:1];
        }
    } else if (section == 2) {
        //客户信息
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@(%@项必填)",[_titleDataArray objectAtIndex:2],gdTJString1]];
        [str addAttribute:NSForegroundColorAttributeName value:[UIColor colorFromHexCode:@"#1A1A1A"] range:NSMakeRange(0,6)];
        [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(6,str.length-6)];
        titleLabel.attributedText = str;
        if (![gdTJString1 isEqualToString:@"0"]) {
            if ([NSString isStringEmpty2:gdTJString1] == NO) {
                titleLabel.attributedText = str;
            }else {
                titleLabel.text = @"(项必填)";
            }
        }else {
            titleLabel.text = [_titleDataArray objectAtIndex:2];
        }
    }
    return view;
}

//每个row高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 5) {
            return _fenqu0_h7;
        } else if (indexPath.row == 6) {
            return _fenqu0_h8;
        } else if (indexPath.row == 7) {
            return _fenqu0_h9;
        } else if (indexPath.row == 8) {
            return _fenqu0_h10;
        } else if (indexPath.row == 11) {
            if (_gtTextFieldHeight == 0) {
                _gtTextFieldHeight = 34;
            }
            return _gtTextFieldHeight + 16;
        }else if (indexPath.row == 14) { // 沟通内容；
            if (_gtTextFieldHeight1 == 0) {
                _gtTextFieldHeight1 = 34;
            }
            return _gtTextFieldHeight1 + 16;
        }
        return 50;
    } else if (indexPath.section == 1) {
        if (indexPath.row == 1) {
            return _fenqu1_h1;
        }else if (indexPath.row == 4) {
            return _fenqu1_h5;
        }
        return 50;
    }
    return 50;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *CellIdentifier = @"AddSubscriptionCellId";
    AddSubscriptionCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"AddSubscriptionCell" owner:self options:nil] lastObject];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    NSString *indexStr = [NSString stringWithFormat:@"%ld",indexPath.section];

    if ([_djString isEqualToString:@"A"]) {//A
        if ([indexStr isEqualToString:@"1"]) {
            if (indexPath.row == 0 || indexPath.row == 3 || indexPath.row == 5 ||  indexPath.row == 9 || indexPath.row == 10 ) {
                cell.biaoxinL.hidden = NO;
                cell.biaoxinL.text = @"*";
            }
        } else if ([indexStr isEqualToString:@"2"]) {
            if (indexPath.row == 0 || indexPath.row == 1 || indexPath.row == 2 ) {
                cell.biaoxinL.hidden = NO;
                cell.biaoxinL.text = @"*";
            }
        }
    }

    if (indexPath.section == 0) {
        //第0分区
        cell.titleLabel.text = [_fenquDataArr0 objectAtIndex:indexPath.row];
        cell.titleLabel.font = [UIFont systemFontOfSize:15];
        UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
        lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
        [cell addSubview:lineImage];
        
        [cell.seleBtn addTarget:self action:@selector(addKHfenqu0BtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        if (indexPath.row == 0) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            _nameTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-40, 15, 200, 20)];
            _nameTextField.delegate = self;
            _nameTextField.returnKeyType =UIReturnKeyDone;
            _nameTextField.textAlignment = NSTextAlignmentRight;
            [cell addSubview:_nameTextField];
            _nameTextField.font = [UIFont systemFontOfSize:15];
            if ([NSString isStringEmpty2:_nameString] == NO) {
                _nameTextField.text = _nameString;
            }else {
                _nameTextField.placeholder = @"请输入姓名";
            }
            _xjBtn = [UIButton buttonWithType: UIButtonTypeSystem];
            _xjBtn.frame = CGRectMake(EMM_WIDTH-50, 0, 40, 40);
            [_xjBtn addTarget:self action:@selector(xjBtnClick:) forControlEvents:UIControlEventTouchUpInside];
            [cell addSubview:_xjBtn];
            _xjImageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-30, 15, 20, 20)];
            
            [cell addSubview:_xjImageView];
            
            if ([_xjNumber isEqualToString:@"0"]) {
                _xjImageView.image = [UIImage imageNamed:@"star2"];
            }else {
                _xjImageView.image = [UIImage imageNamed:@"star"];
            }
        }else if (indexPath.row == 1) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_sexString] == NO) {
                cell.subTitleLabel.text = _sexString;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }else {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }
            cell.seleBtn.hidden = NO;
            cell.seleBtn.tag = 101;
        }else if (indexPath.row == 2) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            _phonTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-10, 15, 200, 20)];
            _phonTextField.delegate = self;
            _phonTextField.returnKeyType =UIReturnKeyDone;
            _phonTextField.textAlignment = NSTextAlignmentRight;
            _phonTextField.keyboardType = UIKeyboardTypeNumberPad;
            [cell addSubview:_phonTextField];
            _phonTextField.font = [UIFont systemFontOfSize:15];
            if ([NSString isStringEmpty2:_phonSting] == NO) {
                _phonTextField.text = _phonSting;
            }else {
                _phonTextField.placeholder = @"请输入手机号";
            }
        }else if (indexPath.row == 3) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_djString] == NO) {
                cell.subTitleLabel.text = _djString;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }else {
                cell.subTitleLabel.text = @"请选择意向等级";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }
            cell.seleBtn.hidden = NO;
            cell.seleBtn.tag = 103;
        }
//        else if (indexPath.row == 4) {
//            cell.biaoxinL.hidden = NO;
//            cell.biaoxinL.text = @"*";
//            cell.btn_qiaoJImageV.hidden = NO;
//            if ([NSString isStringEmpty2:_lyStrting] == NO) {
//                cell.subTitleLabel.text = _lyStrting;
//                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
//            }else {
//                cell.subTitleLabel.text = @"请选择客户性质";
//                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
//            }
//            cell.seleBtn.hidden = NO;
//            cell.seleBtn.tag = 104;
//        }else if (indexPath.row == 5) {
//            cell.biaoxinL.hidden = NO;
//            cell.biaoxinL.text = @"*";
//            cell.btn_qiaoJImageV.hidden = NO;
//            if ([NSString isStringEmpty2:_ztString] == NO) {
//                cell.subTitleLabel.text = _ztString;
//                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
//            }else {
//                cell.subTitleLabel.text = @"请选择客户状态";
//                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
//            }
//            cell.seleBtn.hidden = NO;
//            cell.seleBtn.tag = 105;
//        }
        else if (indexPath.row == 4) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_informedwayEnumName] == NO) {
                cell.subTitleLabel.text = _informedwayEnumName;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }else {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }
            cell.seleBtn.hidden = NO;
            cell.seleBtn.tag = 106;
        }else if (indexPath.row == 5) {
            if (_fenqu0_h7 == 0) {
                cell.titleLabel.hidden = YES;
            }else {
                cell.biaoxinL.hidden = [_informedwayEnumName isEqualToString:@"全员营销"];
                cell.biaoxinL.text = @"*";
                cell.btn_qiaoJImageV.hidden = NO;
                if ([NSString isStringEmpty2:_recommendedCategoryEnumName] == NO) {
                    cell.subTitleLabel.text = _recommendedCategoryEnumName;
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                }else {
                    cell.subTitleLabel.text = @"未选择";
                    cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
                }
            }
            cell.seleBtn.hidden = NO;
            cell.seleBtn.tag = 107;
        }else if (indexPath.row == 6) {
            if (_fenqu0_h8 == 0) {
                cell.titleLabel.hidden = YES;
            }else {
                cell.biaoxinL.hidden = [_informedwayEnumName isEqualToString:@"全员营销"];
                cell.biaoxinL.text = @"*";
                _recommendedNameTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-10, 15, 200, 20)];
                _recommendedNameTextField.delegate = self;
                _recommendedNameTextField.returnKeyType =UIReturnKeyDone;
                _recommendedNameTextField.textAlignment = NSTextAlignmentRight;
                _recommendedNameTextField.font = [UIFont systemFontOfSize:15];
                [cell addSubview:_recommendedNameTextField];
                if ([NSString isStringEmpty2:_recommendedName] == NO) {
                    _recommendedNameTextField.text = _recommendedName;
                }else {
                    _recommendedNameTextField.placeholder = @"请输入推荐人姓名";
                }
            }
        }else if (indexPath.row == 7) {
            if (_fenqu0_h9 == 0) {
                cell.titleLabel.hidden = YES;
            }else {
                cell.biaoxinL.hidden = [_informedwayEnumName isEqualToString:@"全员营销"];
                cell.biaoxinL.text = @"*";
                //recommendedUnitTextField recommendedMobileTextField
                _recommendedMobileTextField = [[UITextField alloc] initWithFrame:CGRectMake(EMM_WIDTH-200-10, 15, 200, 20)];
                _recommendedMobileTextField.delegate = self;
                _recommendedMobileTextField.returnKeyType =UIReturnKeyDone;
                _recommendedMobileTextField.textAlignment = NSTextAlignmentRight;
                _recommendedMobileTextField.font = [UIFont systemFontOfSize:15];
                [cell addSubview:_recommendedMobileTextField];
                if ([NSString isStringEmpty2:_recommendedMobile] == NO) {
                    _recommendedMobileTextField.text = _recommendedMobile;
                }else {
                    _recommendedMobileTextField.placeholder = @"请输入推荐人手机号";
                }
            }
        }else if (indexPath.row == 8) {
            if (_fenqu0_h10 == 0) {
                cell.titleLabel.hidden = YES;
            }else {
                cell.biaoxinL.hidden = [_informedwayEnumName isEqualToString:@"全员营销"];
                cell.biaoxinL.text = @"*";
                _recommendedUnitTextField = [[UITextField alloc] initWithFrame:CGRectMake(80, 15, EMM_WIDTH - 80 - 10, 20)];
                _recommendedUnitTextField.delegate = self;
                _recommendedUnitTextField.returnKeyType =UIReturnKeyDone;
                _recommendedUnitTextField.textAlignment = NSTextAlignmentRight;
                _recommendedUnitTextField.font = [UIFont systemFontOfSize:15];
                [cell addSubview:_recommendedUnitTextField];
                if ([NSString isStringEmpty2:_recommendedUnit] == NO) {
                    _recommendedUnitTextField.text = _recommendedUnit;
                }else {
                    _recommendedUnitTextField.placeholder = @"请输入推荐人单位";
                }
            }
        } else if (indexPath.row == 9) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_scjcFSSting] == YES) {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }else {
                cell.subTitleLabel.text = _scjcFSSting;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }
            cell.seleBtn.hidden = self.isflg;
            cell.seleBtn.tag = 111;
        } else if (indexPath.row == 10) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_scjcSJSting] == YES) {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }else {
                cell.subTitleLabel.text = _scjcSJSting;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }
            cell.seleBtn.hidden = NO;
            cell.seleBtn.tag = 112;
        } else if (indexPath.row == 11) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.seleBtn.hidden = YES;
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
            CGSize textSize = [@"沟通内容" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
            _gtTextField= [[UITextView alloc] initWithFrame:CGRectMake(textSize.width + 30, 5, EMM_WIDTH-textSize.width - 30 - 10, _gtTextFieldHeight + 6)];
            _gtTextField.delegate = self;
            _gtTextField.returnKeyType =UIReturnKeyDone;
            _gtTextField.textAlignment = NSTextAlignmentRight;
            [cell addSubview:_gtTextField];
            _gtTextField.font = [UIFont systemFontOfSize:15];
            if ([NSString isStringEmpty2:_scGTSting] == NO) {
                _gtTextField.text = _scGTSting;
                _gtTextField.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }else {
                _gtTextField.text = @"沟通内容";
                _gtTextField.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            }
            lineImage.frame = CGRectMake(10, _gtTextFieldHeight + 16 - 0.5, EMM_WIDTH - 20, 0.5);
            lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            [cell addSubview:lineImage];
        } else if (indexPath.row == 12) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:self.getCustomerDetail.ftContactWay1] == YES) {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }else {
                cell.subTitleLabel.text = self.getCustomerDetail.ftContactWay1;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }
            cell.seleBtn.hidden = YES;
            cell.seleBtn.tag = 111;
        } else if (indexPath.row == 13) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:self.getCustomerDetail.ftContactTime1] == YES) {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }else {
                cell.subTitleLabel.text = self.getCustomerDetail.ftContactTime1;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }
            cell.seleBtn.hidden = NO;
            cell.seleBtn.tag = 112;
        } else if (indexPath.row == 14) {
            cell.biaoxinL.hidden = NO;
            cell.biaoxinL.text = @"*";
            cell.seleBtn.hidden = YES;
            NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],};
            CGSize textSize = [@"沟通内容" boundingRectWithSize:CGSizeMake(100, 100) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
            _gtTextField1= [[UITextView alloc] initWithFrame:CGRectMake(textSize.width + 30, 5, EMM_WIDTH-textSize.width - 30 - 10, _gtTextFieldHeight1 + 6)];
            _gtTextField1.delegate = self;
            _gtTextField1.returnKeyType =UIReturnKeyDone;
            _gtTextField1.textAlignment = NSTextAlignmentRight;
            [cell addSubview:_gtTextField1];
            _gtTextField1.font = [UIFont systemFontOfSize:15];
            if ([NSString isStringEmpty2:self.scGTString1] == NO) {
                _gtTextField1.text = self.scGTString1;
                _gtTextField1.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }else {
                _gtTextField1.text = @"沟通内容";
                _gtTextField1.textColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            }
            lineImage.frame = CGRectMake(10, _gtTextFieldHeight1 + 16 - 0.5, EMM_WIDTH - 20, 0.5);
            lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
            [cell addSubview:lineImage];
        }

    } else if (indexPath.section == 1) {
        //第1分区
        cell.titleLabel.text = [_fenquDataArr1 objectAtIndex:indexPath.row];
        cell.titleLabel.font = [UIFont systemFontOfSize:15];
        UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
        lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
        [cell addSubview:lineImage];
        
        [cell.seleBtn addTarget:self action:@selector(addKHfenqu1BtnClick:) forControlEvents:UIControlEventTouchUpInside];
        cell.seleBtn.hidden = NO;
        cell.seleBtn.tag = indexPath.row;
        
        if (indexPath.row == 0) {
            //置业动机
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty:_zyjdString] == YES) {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            } else {
                cell.subTitleLabel.text = _zyjdString;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }
        } else if (indexPath.row == 1) {
            //关注重点
            NSInteger h = 0;
            if ([_djString isEqualToString:@"A"]) {
                h = 20;
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 10, 40)];
                label.text = @"*";
                label.textColor = [UIColor redColor];
                label.font = [UIFont systemFontOfSize:20];
                [cell addSubview:label];
            }else {
                h = 10;
            }
            UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(h, 15, 100, 20)];
            nameL.text = @"关注重点";
            nameL.font = [UIFont systemFontOfSize:15];
            nameL.textColor = [UIColor colorFromHexCode:@"#5A5A5A"];
            [cell addSubview:nameL];
            cell.titleLabel.hidden = YES;
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-40, 10, 30, 30)];
            imageView.image = [UIImage imageNamed:@"rc_add"];
            [cell addSubview:imageView];
            
            for (int i = 0; i < _gzzdArr.count; i++) {
                NSString *gzString = [_gzzdArr objectAtIndex:i];
                UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 50+i*50, EMM_WIDTH, 50)];
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(EMM_WIDTH-40, 10, 30, 30);
                [button setImage:[UIImage imageNamed:@"rc_dlet"] forState:UIControlStateNormal];
                button.tag =  i;
                [button addTarget:self action:@selector(gzzjBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                [view addSubview:button];
                [cell addSubview:view];
                
                UILabel *touistsTLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 10, 10)];
                touistsTLabel.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
                touistsTLabel.layer.masksToBounds = YES;
                touistsTLabel.layer.cornerRadius = 5;
                [view addSubview:touistsTLabel];
                
                UILabel *touistsNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 0, EMM_WIDTH-35, 50)];
                touistsNameLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                touistsNameLabel.font = [UIFont systemFontOfSize:15];
                touistsNameLabel.textAlignment = NSTextAlignmentLeft;
                touistsNameLabel.text = gzString;
                touistsNameLabel.numberOfLines = 0;
                [view addSubview:touistsNameLabel];
                
                UIImageView *V1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
                V1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [view addSubview:V1];
            }
            
        } else if (indexPath.row == 2) {
            //需求面积
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_xqmjString] == NO) {
                cell.subTitleLabel.text = _xqmjString;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }else {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }
           
            cell.biaoxinL.hidden = ![self.djString isEqualToString:@"A"];
            cell.biaoxinL.text = @"*";
            
        } else if (indexPath.row == 3) {
            //付款方式
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty:_fkfsString] == YES) {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }else {
                cell.subTitleLabel.text = _fkfsString;
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
            }
        }
//        else if (indexPath.row == 4) {
//            //意向房源
//            NSInteger h = 0;
//            if ([_djString isEqualToString:@"A"]) {
//                h = 20;
//                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 10, 40)];
//                label.text = @"*";
//                label.textColor = [UIColor redColor];
//                label.font = [UIFont systemFontOfSize:20];
//                [cell addSubview:label];
//            }else {
//                h = 10;
//            }
//            UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(h, 15, 100, 20)];
//            nameL.text = @"意向房源";
//            nameL.font = [UIFont systemFontOfSize:15];
//            nameL.textColor = [UIColor colorFromHexCode:@"#5A5A5A"];
//            [cell addSubview:nameL];
//            cell.titleLabel.hidden = YES;
//            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-40, 10, 30, 30)];
//            imageView.image = [UIImage imageNamed:@"rc_add"];
//            [cell addSubview:imageView];
//            for (int i = 0; i < _housingArr.count; i++) {
//                NSString *gzString = [_housingArr objectAtIndex:i];
//                UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 50+i*50, EMM_WIDTH, 50)];
//                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//                button.frame = CGRectMake(EMM_WIDTH-40, 10, 30, 30);
//                [button setImage:[UIImage imageNamed:@"rc_dlet"] forState:UIControlStateNormal];
//                button.tag =  i;
//                [button addTarget:self action:@selector(yxfyBtnClick:) forControlEvents:UIControlEventTouchUpInside];
//                [view addSubview:button];
//                [cell addSubview:view];
//
//                UILabel *touistsTLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 10, 10)];
//                touistsTLabel.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
//                touistsTLabel.layer.masksToBounds = YES;
//                touistsTLabel.layer.cornerRadius = 5;
//                [view addSubview:touistsTLabel];
//
//                UILabel *touistsNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 0, EMM_WIDTH-65, 50)];
//                touistsNameLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
//                touistsNameLabel.font = [UIFont systemFontOfSize:15];
//                touistsNameLabel.textAlignment = NSTextAlignmentLeft;
//                touistsNameLabel.text = gzString;
//                touistsNameLabel.numberOfLines = 0;
//                [view addSubview:touistsNameLabel];
//
//                UIImageView *V1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
//                V1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
//                [view addSubview:V1];
//            }
//        }
        else if (indexPath.row == 4) {
            //生活服务
            cell.btn_qiaoJImageV.hidden = YES;
            cell.biaoxinL.hidden = YES;
            NSInteger h = 0;
            if ([_djString isEqualToString:@"A"]) {
                h = 20;
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 10, 40)];
                label.text = @"*";
                label.textColor = [UIColor redColor];
                label.font = [UIFont systemFontOfSize:20];
                [cell addSubview:label];
            }else {
                h = 10;
            }
            UILabel *nameL = [[UILabel alloc] initWithFrame:CGRectMake(h, 15, 100, 20)];
            nameL.text = @"生活服务";
            nameL.font = [UIFont systemFontOfSize:15];
            nameL.textColor = [UIColor colorFromHexCode:@"#5A5A5A"];
            [cell addSubview:nameL];
            cell.titleLabel.hidden = YES;
            UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(EMM_WIDTH-40, 10, 30, 30)];
            imageView.image = [UIImage imageNamed:@"rc_add"];
            [cell addSubview:imageView];
            
            for (int i = 0; i < _rqServicesNameArr.count; i++) {
                NSString *gzString = [_rqServicesNameArr objectAtIndex:i];
                UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 50+i*50, EMM_WIDTH, 50)];
                UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
                button.frame = CGRectMake(EMM_WIDTH-40, 10, 30, 30);
                [button setImage:[UIImage imageNamed:@"rc_dlet"] forState:UIControlStateNormal];
                button.tag =  i;
                [button addTarget:self action:@selector(rqServicesBtnClick:) forControlEvents:UIControlEventTouchUpInside];
                [view addSubview:button];
                [cell addSubview:view];
                
                UILabel *touistsTLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 20, 10, 10)];
                touistsTLabel.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
                touistsTLabel.layer.masksToBounds = YES;
                touistsTLabel.layer.cornerRadius = 5;
                [view addSubview:touistsTLabel];
                
                UILabel *touistsNameLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, 0, EMM_WIDTH-35, 50)];
                touistsNameLabel.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
                touistsNameLabel.font = [UIFont systemFontOfSize:15];
                touistsNameLabel.textAlignment = NSTextAlignmentLeft;
                touistsNameLabel.text = gzString;
                touistsNameLabel.numberOfLines = 0;
                [view addSubview:touistsNameLabel];
                
                UIImageView *V1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
                V1.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
                [view addSubview:V1];
            }
            
        }
    } else if (indexPath.section == 2) {
        //第3分区
        cell.titleLabel.text = [_fenquDataArr3 objectAtIndex:indexPath.row];
        cell.titleLabel.font = [UIFont systemFontOfSize:15];
        UIImageView *lineImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 49.5, EMM_WIDTH-20, 0.5)];
        lineImage.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
        [cell addSubview:lineImage];
        
        [cell.seleBtn addTarget:self action:@selector(addKHfenqu3BtnClick:) forControlEvents:UIControlEventTouchUpInside];
        cell.seleBtn.hidden = NO;
        cell.seleBtn.tag = indexPath.row;
        if (indexPath.row == 0) {
            //居住区
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_khJZQSting] == NO) {
                cell.subTitleLabel.text = _khJZQSting;
                cell.subTitleLabel.textColor = [UIColor blackColor];
            }else {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }
        } else if (indexPath.row == 1) {
            //工作区
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_khGZQSting] == NO) {
                cell.subTitleLabel.text = _khGZQSting;
                cell.subTitleLabel.textColor = [UIColor blackColor];
            }else {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }
        }else if (indexPath.row == 2) {
            //从事行业
            cell.btn_qiaoJImageV.hidden = NO;
            if ([NSString isStringEmpty2:_khCszyString] == YES) {
                cell.subTitleLabel.text = @"未选择";
                cell.subTitleLabel.textColor = [UIColor colorFromHexCode:@"#C8C8C8"];
            }else {
                cell.subTitleLabel.text = _khCszyString;
                cell.subTitleLabel.textColor = [UIColor blackColor];
            }
        }
    }
    return cell;
}

#pragma mark - 公共方法调用
-(void)doButton:(UIButton *)sender {
    NSString *string = [NSString stringWithFormat:@"%ld",sender.tag-100];
    //数组selectedArr里面存的数据和表头想对应，方便以后做比较
    if ([_selectedArr containsObject:string]) {
        [_selectedArr removeObject:string];
    } else {
        [_selectedArr addObject:string];
    }
    [_customersTableView reloadData];
}

- (void)checkPhoneNumberlegal:(NSString *)phoneNumber {
//    NSString *path = [NSString stringWithFormat:@"%@/appapi/verifyingMobile",apiBaseUrl];
//    NSString *data = [@{@"params" : phoneNumber} JSONString];
//    AFHTTPRequestSerializer *seria = [AFHTTPRequestSerializer serializer];
//    [AFHTTPSessionManager manager].requestSerializer = seria;
//
//    [AFHTTPSessionManager manager].responseSerializer.acceptableContentTypes =[NSSet setWithObjects:@"text/html",@"application/json", @"text/json" ,@"text/javascript", nil];
//    [[AFHTTPSessionManager manager]POST:path parameters:@{@"body": data} success:^(NSURLSessionDataTask *task, id responseObject) {
//        
//    } failure:^(NSURLSessionDataTask *task, NSError *error) {
//        
//    }];
    
  checkPhoneNumberApi *api = [[checkPhoneNumberApi alloc]initWithPhoneNumber:phoneNumber];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        NSDictionary *resultData = request.responseJSONObject[@"resData"];
        NSString *type = resultData[@"flag"];
        if (![type isEqualToString:@"1"]) {
              [self showToast:@"请输入正确的手机号"];
            _phonTextField.text = @"";
        }else {
             _phonSting = phoneNumber;
           [self CheckCustomerPhoneApiPhone:_phonSting peMobile:nil isDistinguish:@"1"];
        }
        
    } failure:^(YTKBaseRequest *request) {
       
    }];
    
    
//    if (![textField.text isMobileNumberClassification]) {
//        [self showToast:@"请输入正确的手机号"];
//    } else {
//        _phonSting = textField.text;
//        [self CheckCustomerPhoneApiPhone:_phonSting peMobile:nil isDistinguish:@"1"];
//    }
}

#pragma mark - UITextFieldDelegate
-(void)textFieldDidEndEditing:(UITextField *)textField {
    if (textField == _nameTextField) {
        if (textField.text.length > 30) {
            _nameString = @"";
            _nameTextField.text = @"";
            [self showToast:@"名字不能超过30个字符"];
            return;
        }
        _nameString = textField.text;
    } else if (textField == _phonTextField) {
        if (textField.text.length > 0) {
            NSString *phone = [self adjustStringWithPhoneNumber:textField.text];
            if (phone.length == 11) {
                [self checkPhoneNumberlegal:phone];
            } else {
                [self showToast:@"输入手机号位数不对"];
            }
        } else {
            [self showToast:@"手机号不能为空"];
        }
    } else if (textField == _recommendedNameTextField) {
        _recommendedName = textField.text;
    } else if (textField == _recommendedMobileTextField) {
        _recommendedMobile = textField.text;
    } else if (textField == _recommendedUnitTextField) {
        _recommendedUnit = textField.text;
    }
}

- (NSString *)adjustStringWithPhoneNumber:(NSString *)number {
    NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
    int i = 0;
    NSString *resultStr = number;
    while (i < number.length) {
        NSString * tempString = [number substringWithRange:NSMakeRange(i, 1)];
        NSRange range = [tempString rangeOfCharacterFromSet:tmpSet];
        // 如果包含特殊字符替换为空
        if (range.length == 0) {
            resultStr = [resultStr stringByReplacingOccurrencesOfString:tempString withString:@""];
        }
        i++;
    }
    if ([resultStr containsString:@"+"]) {
        resultStr = [resultStr stringByReplacingOccurrencesOfString:@"+" withString:@""];
    }
    if ([resultStr containsString:@" "]) {
        resultStr = [resultStr stringByReplacingOccurrencesOfString:@" " withString:@""];
    }
    return resultStr;
}

#pragma mark - UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView{
    if (textView == _gtTextField) {//首次接触信息-沟通内容
        if ([textView.text isEqualToString:@"沟通内容"]) {
            textView.text = nil;
            _gtTextField.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
        }else{
            _gtTextField.textColor = [UIColor colorFromHexCode:@"#1A1A1A"];
        }
    }
}
- (void)textViewDidChange:(UITextView *)textView {
    if (textView == _gtTextField) {//首次接触信息-沟通内容
        _scGTSting = textView.text;
        _gtTextFieldHeight = [self heightForString:_gtTextField andWidth:EMM_WIDTH - 100];
    }else {
        self.scGTString1 = textView.text;
        _gtTextFieldHeight1 = [self heightForString:_gtTextField1 andWidth:EMM_WIDTH - 100];
    }
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    [_customersTableView reloadData];
}
//计算textView的高度
- (float) heightForString:(UITextView *)textView andWidth:(float)width{
    CGSize sizeToFit = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
    return sizeToFit.height;
}

#pragma mark - 第0分区所有方法调用
//选择星级按钮调用方法
- (void)xjBtnClick:(UIButton *)btn {
    if (_isXj == YES) {
        _xjImageView.image = [UIImage imageNamed:@"star2"];
        _xjNumber = @"0";
        _isXj = NO;
    } else {
        _xjImageView.image = [UIImage imageNamed:@"star"];
        _xjNumber = @"1";
        _isXj = YES;
    }
    [_customersTableView reloadData];
}

//第0分区cell 按钮选择

- (void)addKHfenqu0BtnClick:(UIButton *)btn {
    [_phonTextField resignFirstResponder];
    [_nameTextField resignFirstResponder];
    if (btn.tag == 101) {
        NSArray *arr = [NSArray arrayWithObjects:@"男",@"女", nil];
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:nil titleNmae:@"请选择性别" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor colorFromHexCode:@"#1A1A1A"] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _sexString = indet;
                _sexNumber = number;
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 103) {
        
        if ([_isTransaction isEqualToString:@"1"]) {
            return;
        }
        
        NSArray *arr = [NSArray arrayWithObjects:@"A",@"B",@"C",@"D", nil];
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:nil titleNmae:@"选择意向等级" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor colorFromHexCode:@"#1A1A1A"] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            NSLog(@"%@",indet);
            if ([NSString isStringEmpty2:indet] == NO) {
                _djString = indet;
                _djNumber = [NSString stringWithFormat:@"%ld", [number integerValue] + 1];
                if ([_djString isEqualToString:@"A"]) {//A
                    gdTJString1 = @"3";
                    xuqiuXXString = @"6";
                }else if ([_djString isEqualToString:@"B"]) {//B
                    gdTJString1 = @"0";
                    xuqiuXXString = @"0";

                }else if ([_djString isEqualToString:@"C"]) {//c
                    gdTJString1 = @"0";
                    xuqiuXXString = @"0";
                }else if([_djString isEqualToString:@"D"]) {
                    gdTJString1 = @"0";
                    xuqiuXXString = @"0";
                }else {
                    gdTJString1 = @"0";
                    xuqiuXXString = @"0";
                }
                _selectedArr = [[NSMutableArray alloc] initWithObjects:@"0",@"1",@"2", nil];
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 104) {
        if (_khxzList.count == 0) {
            [self showToast:@"暂无可选项"];
            return;
        }
        NSMutableArray *arr = [[NSMutableArray alloc] init];
        for (int i = 0; i < _khxzList.count; i++) {
            NSMutableDictionary *dict = [_khxzList objectAtIndex:i];
            [arr addObject:[dict objectForKey:@"dictionaryName"]];
        }
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"选择客户性质" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor colorFromHexCode:@"#1A1A1A"] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            NSLog(@"%@",indet);
            if ([NSString isStringEmpty2:indet] == NO) {
                _lyStrting = indet;
                
                for (int i = 0; i < _khxzList.count; i++) {
                    NSMutableDictionary *dict = [_khxzList objectAtIndex:i];
                    if ([_lyStrting isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                        _lyNumber = [dict objectForKey:@"dictionaryId"];
                    }
                }
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 105) {
        if ([_ztString isEqualToString:@"认筹"] || [_ztString isEqualToString:@"认购"] || [_ztString isEqualToString:@"签约"]) {
            [self showToast:@"该客户处于交易状态不能更改状况"];
            return;
        }
        NSArray *arr = [NSArray arrayWithObjects:@"问询", @"来访",@"无意向",nil];
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"选择客户状态" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor colorFromHexCode:@"#1A1A1A"] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _ztString = indet;
                if ([indet isEqualToString:@"无意向"]) {
                    _ztNumber = @"6";
                }else {
                    _ztNumber = number;
                }
            }
            
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 106) {
        if (_hztjList.count == 0) {
            [self showToast:@"暂无可选项"];
            return;
        }
        NSMutableArray *arr = [[NSMutableArray alloc] init];
        for (int i = 0; i < _hztjList.count; i++) {
            NSMutableDictionary *dict = [_hztjList objectAtIndex:i];
            [arr addObject:[dict objectForKey:@"dictionaryName"]];
        }
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"选择获知途径" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor colorFromHexCode:@"#1A1A1A"] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _informedwayEnumName = indet;
                _recommendedCategoryEnumName = nil;
                _recommendedCategoryEnum = nil;
                _recommendedName = nil;
                _recommendedMobile = nil;
                _recommendedUnit = nil;
                for (int i = 0; i < _hztjList.count; i++) {
                    NSMutableDictionary *dict = [_hztjList objectAtIndex:i];
                    if ([_informedwayEnumName isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                        _informedWay = [dict objectForKey:@"dictionaryId"];
                    }
                }
                if ([_informedwayEnumName isEqualToString:@"外部推荐"] ||[_informedwayEnumName isEqualToString:@"全员营销"] ) {
                    _fenqu0_h7 = 50;
                    _fenqu0_h8 = 50;
                    _fenqu0_h9 = 50;
                    _fenqu0_h10 = 50;
                } else {
                    _fenqu0_h7 = 0;
                    _fenqu0_h8 = 0;
                    _fenqu0_h9 = 0;
                    _fenqu0_h10 = 0;
                }
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 107) {
        NSArray *arr = [NSArray arrayWithObjects:
                        @"分销/中介",@"老客户(未成交客户)",@"老业主",nil];
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"请选择推荐人类别" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor colorFromHexCode:@"#1A1A1A"] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _recommendedCategoryEnumName = indet;
                _recommendedCategoryEnum = number;
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 111) {
        if (_tcfsList.count == 0) {
            [self showToast:@"暂无可选项"];
            return;
        }
        NSMutableArray *arr = [[NSMutableArray alloc] init];
        for (int i = 0; i < _tcfsList.count; i++) {
            NSMutableDictionary *dict = [_tcfsList objectAtIndex:i];
            [arr addObject:[dict objectForKey:@"dictionaryName"]];
        }
        
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"首次接触方式" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _scjcFSSting = indet;
                for (int i = 0; i < _tcfsList.count; i++) {
                    NSMutableDictionary *dict = [_tcfsList objectAtIndex:i];
                    if ([_scjcFSSting isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                        _scjcNumber = [dict objectForKey:@"dictionaryId"];
                    }
                }
            }
            
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 112) {
        
    }
    
}

#pragma mark - 第1分区所有方法调用
- (void)addKHfenqu1BtnClick:(UIButton *)btn {
    if (btn.tag == 0) {
        //置业动机
        if (_zydjList.count == 0) {
            [self showToast:@"暂无可选项"];
            return;
        }
        NSMutableArray *arr = [[NSMutableArray alloc] init];
        for (int i = 0; i < _zydjList.count; i++) {
            NSMutableDictionary *dict = [_zydjList objectAtIndex:i];
            [arr addObject:[dict objectForKey:@"dictionaryName"]];
        }
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"请选择置业动机" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _zyjdString = indet;
                for (int i = 0; i < _zydjList.count; i++) {
                    NSMutableDictionary *dict = [_zydjList objectAtIndex:i];
                    if ([_zyjdString isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                        _zyjdNumber = [dict objectForKey:@"dictionaryId"];
                    }
                }
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 1) {
        //关注重点
        if (_rqFocusList.count == 0) {
            [self showToast:@"暂无可选项"];
            return;
        }
        
        AttentionHuxingViewController *avn = [[AttentionHuxingViewController alloc] init];
        avn.focusArr = _rqFocusList;
        avn.foas = @"2";
        avn.titleString = @"关注重点";
        avn.recordArr = _gzzdArr;
        avn.huxingBlock =  ^(NSMutableArray *arr,NSMutableArray *arrId) {
            [_gzzdArr removeAllObjects];
            [_gzzdIdArr removeAllObjects];
            _gzzdArr = arr;
            _gzzdIdArr = arrId;
            _gzzdNumber = [_gzzdIdArr componentsJoinedByString:@","];
            _fenqu1_h1 = 50+(int)_gzzdArr.count*50;
            [_customersTableView reloadData];
        };
        [self.navigationController pushViewController:avn animated:YES];
    } else if (btn.tag == 2) {
        NSArray *arr = [NSArray arrayWithObjects:
                        @"50㎡以下",@"50-70㎡",@"70-90㎡",
                        @"90-120㎡", @"120-140㎡",@"140-160㎡",@"160-180㎡",@"180-200㎡",@"200㎡以上",nil];
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"选择需求面积" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _xqmjString = indet;
                _xqmjNumber = number;
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    } else if (btn.tag == 3) {
        NSArray *arr = [NSArray arrayWithObjects:
                        @"一次性付款",@"分期付款",@"商业按揭",
                        @"公积金按揭 ", @"组合贷款", nil];
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"选项" titleNmae:@"请选择付款方式" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _fkfsString = indet;
                _fkfsNumber = number;
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    }
//        else if (btn.tag == 4) {
//        HousingViewController *hvn = [[HousingViewController alloc] init];
//        [hvn setHousingNewBlock:^(NSMutableArray *arr, NSString *strName) {
//            RoomList *roomList = [arr objectAtIndex:0];
//            NSString *strUrl = [strName stringByReplacingOccurrencesOfString:@"-->" withString:@"-"];
//            [_housingArr addObject:strUrl];
//            [_housingArrId addObject:@{@"roomId":roomList.roomId}];
//
//            NSMutableArray *listAry = [[NSMutableArray alloc]init];
//            for (NSString *str in _housingArr) {
//                if (![listAry containsObject:str]) {
//                    [listAry addObject:str];
//                }
//            }
//            _housingArr = listAry;
//
//            NSMutableArray *listAryId = [[NSMutableArray alloc]init];
//            for (NSString *str in _housingArrId) {
//                if (![listAryId containsObject:str]) {
//                    [listAryId addObject:str];
//                }
//            }
//            _housingArrId = listAryId;
//            _fenqu1_h4 = 50+(int)_housingArr.count*50;
//            [_customersTableView reloadData];
//        }];
//        [self.navigationController pushViewController:hvn animated:YES];
//
//    }
        else if (btn.tag == 4) {
        if (_rqServicesList.count == 0) {
            [self showToast:@"暂无可选项"];
            return;
        }
    
        AttentionHuxingViewController *avn = [[AttentionHuxingViewController alloc] init];
        avn.focusArr = _rqServicesList;
        avn.foas = @"2";
        avn.titleString = @"生活服务";
        avn.recordArr = _rqServicesNameArr;
        avn.huxingBlock =  ^(NSMutableArray *arr,NSMutableArray *arrId) {
            [_rqServicesNameArr removeAllObjects];
            [_rqServicesIdArr removeAllObjects];
            _rqServicesNameArr = arr;
            _rqServicesIdArr = arrId;
            _fwNumber = [_rqServicesIdArr componentsJoinedByString:@","];
            _fenqu1_h5 = 50+(int)_rqServicesNameArr.count*50;
            [_customersTableView reloadData];
        };
        [self.navigationController pushViewController:avn animated:YES];
        
    }
}

#pragma mark - 关注重点删除方法
- (void)gzzjBtnClick:(UIButton *)btn {
    [_gzzdArr removeObjectAtIndex:btn.tag];
    [_gzzdIdArr removeObjectAtIndex:btn.tag];
    _gzzdNumber = [_gzzdIdArr componentsJoinedByString:@","];
    _fenqu1_h1 = _gzzdArr.count * 50 + 50;
    [_customersTableView reloadData];
}

#pragma mark - 意向房源型删除方法
- (void)yxfyBtnClick:(UIButton *)btn {
    [_housingArr removeObjectAtIndex:btn.tag];
    [_housingArrId removeObjectAtIndex:btn.tag];
    _fenqu1_h4 = _housingArr.count * 50 + 50;
    [_customersTableView reloadData];
}

                                                      
#pragma mark - 生活服务删除方法
- (void)rqServicesBtnClick:(UIButton *)btn {
  [_rqServicesNameArr removeObjectAtIndex:btn.tag];
  [_rqServicesIdArr removeObjectAtIndex:btn.tag];
  _fwNumber = [_rqServicesIdArr componentsJoinedByString:@","];
  _fenqu1_h5 = _rqServicesNameArr.count * 50 + 50;
  [_customersTableView reloadData];
}

#pragma mark - 第2分区所有方法调用
- (void)addKHfenqu3BtnClick:(UIButton *)btn {
    if (btn.tag == 0) {
        //居住区
        _qbSsqString = @"2";
        _sHQSeleView.hidden = NO;
    } else if (btn.tag == 1) {
        //工作区
        _qbSsqString = @"3";
        _sHQSeleView.hidden = NO;
    } else if (btn.tag == 2) {
        //从事行业
        if (_cshyList.count == 0) {
            [self showToast:@"暂无可选项"];
            return;
        }
        NSMutableArray *arr = [[NSMutableArray alloc] init];
        for (int i = 0; i < _cshyList.count; i++) {
            NSMutableDictionary *dict = [_cshyList objectAtIndex:i];
            [arr addObject:[dict objectForKey:@"dictionaryName"]];
        }
        ShowMenuView *menuView = [[ShowMenuView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) title:@"" titleNmae:@"请选择" numLits:nil items:arr];
        menuView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
        [[UIApplication sharedApplication].keyWindow addSubview:menuView];
        __block ShowMenuView *weakMenuView = menuView;
        __block AddCustomersViewController *blockSelf = self;
        [menuView setTouchBlock:^(NSString *indet, NSString *number) {
            if ([NSString isStringEmpty2:indet] == NO) {
                _khCszyString = indet;
                for (int i = 0; i < _cshyList.count; i++) {
                    NSMutableDictionary *dict = [_cshyList objectAtIndex:i];
                    if ([_khCszyString isEqualToString:[dict objectForKey:@"dictionaryName"]]) {
                        _khCszyIdString = [dict objectForKey:@"dictionaryId"];
                    }

                }
            }
            [weakMenuView removeFromSuperview];
            [blockSelf.customersTableView reloadData];
        }];
    }
}

- (void)creatinitWithButton {
    UIButton *preservationBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    preservationBtn.frame = CGRectMake(10, EMM_HEIGHT-60-SafeAreaTopHeight, EMM_WIDTH-20, 45);
    preservationBtn.backgroundColor = [UIColor colorFromHexCode:@"#ff7200"];
    [preservationBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [preservationBtn setTitle:@"保存" forState:UIControlStateNormal];
    preservationBtn.layer.masksToBounds = YES;
    preservationBtn.layer.cornerRadius = 5;
    preservationBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [preservationBtn addTarget:self action:@selector(preservationBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:preservationBtn];
}

#pragma mark -保存
- (void)preservationBtnClick:(UIButton *)btn {
    NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
    NSString *necessary = [userdf objectForKey:@"necessary"];
    if ([necessary isEqualToString:@"1"]) {
        if (_nameString.length == 0 || _nameString.length > 30) {
            [self showToast:@"客户姓名需大于0小于30个字符"];
            return;
        }
        if (_xjNumber.length == 0) {
            [self showToast:@"星级未选择"];
            return;
        }
        if (_sexString.length == 0) {
            [self showToast:@"性别未填写"];
            return;
        }
        if (_phonSting.length == 0) {
            [self showToast:@"客户电话未填写"];
            return;
        }
        if (_djString.length == 0) {
            [self showToast:@"意向等级未选择"];
            return;
        }
//        if (_lyStrting.length == 0) {
//            [self showToast:@"客户性质未选择"];
//            return;
//        }
//        if (_ztString.length == 0) {
//            [self showToast:@"客户状态未选择"];
//            return;
//        }
        if ([self.djString isEqualToString:@"A"]) { // 客户等级为A时，需求面积为必填
            if(self.xqmjString.length == 0) {
                 [self showToast:@"需求面积未输入"];
                return;
            }
        }
        

        if (_informedWay.length == 0) {
            [self showToast:@"客户获知途径未选择"];
            return;
        }
        
        if ([_informedwayEnumName isEqualToString:@"外部推荐"]) {
            if (_recommendedCategoryEnumName.length == 0) {
                [self showToast:@"推荐人类别未选择"];
                return;
            }
        }
        
        if ([_informedwayEnumName isEqualToString:@"外部推荐"] ) {
            if (_recommendedName.length == 0) {
                [self showToast:@"推荐人姓名未填写"];
                return;
            }
        }
        
        if ([_informedwayEnumName isEqualToString:@"外部推荐"]) {
            if (_recommendedMobile.length == 0) {
                [self showToast:@"推荐人手机号未填写"];
                return;
            }
        }
        
        if (_scjcFSSting.length == 0) {
            [self showToast:@"首次接触方式未选择"];
            return;
        }
        
        if (_scjcSJSting.length == 0) {
            [self showToast:@"首次接触时间未选择"];
            return;
        }
        if (self.isflg && self.getCustomerDetail.ftContactWay1) {
            if (_scGTSting.length == 0 || self.scGTString1 == 0) {
                [self showToast:@"沟通内容未输入"];
                return;
            }
        }else {
            if (_scGTSting.length == 0) {
                [self showToast:@"沟通内容未输入"];
                return;
            }
        }
        [self postCheckCustomerIntentionApi];
    }else {
        [self creatNormalProcess];
    }

}

#pragma mark - 校验意向等级
- (void)postCheckCustomerIntentionApi {
    [self showHud:@"正在加载" inTime:5];
    CheckCustomerIntentionApi *api = [[CheckCustomerIntentionApi alloc] initWithCustomerName:_nameString
                                                                                customerStar:_xjNumber
                                                                                 customerSex:_sexNumber
                                                                               customerPhone:_phonSting
                                                                              intentionLevel:_djNumber
                                                                              customerOrigin:_lyNumber
                                                                              customerStatus:_ztNumber
                                                                              rqTheirMotives:_zyjdNumber
                                                                                   rqFocusId:_gzzdNumber
                                                                             rqPaymentMethod:_fkfsNumber
                                                                                rqServicesId:_fwNumber
                                                                                    roomList:_housingArrId
                                                                                rqDemandArea:_xqmjNumber
                                                                                ftContactWay:_scjcNumber
                                                                               ftContactTime:_scjcSJSting
                                                                            ftContactContent:_scGTSting                                                                       peResidenceProvinceId:_peResidenceProvinceId
                                                                           peResidenceCityId:_peResidenceCityId
                                                                           peResidenceAreaId:_peResidenceAreaId
                                                                      peWorkaroundProvinceId:_peWorkaroundProvinceId
                                                                          peWorkaroundCityId:_peWorkaroundCityId
                                                                          peWorkaroundAreaId:_peWorkaroundAreaId
                                                                                    industry:_khCszyIdString
                                                                                 informedWay:_informedWay
                                                                         recommendedCategory:_recommendedCategoryEnum
                                                                             recommendedName:_recommendedName
                                                                           recommendedMobile:_recommendedMobile
                                                                             recommendedUnit:_recommendedUnit];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        CheckCustomerIntentionApi *result = (CheckCustomerIntentionApi *)request;
        if (result.isSuccess) {
            CheckCustomerIntention *get = result.resultData;
            if ([get.intentionResult isEqualToString:@"1"]) {
                if ([_isTransaction isEqualToString:@"1"]) {
                    [self postEditCustomerApiIntentionLevelRemark:nil intentionLevel:_djNumber];
                }else {
                    if (_isflg == NO) {
                        [self postAddCustomerApiIntentionLevelRemark:nil intentionLevel:_djNumber];
                    }else {
                        [self postEditCustomerApiIntentionLevelRemark:nil intentionLevel:_djNumber];
                    }
                }
            }else {
                if ([_isTransaction isEqualToString:@"1"]) {
                    [self creatIsLVneed];
                }else {
                      [self creatIsLVneed];
                }
            }
        } else {
            //            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}


#pragma mark - 编辑或新增需要完善信息
- (void)creatIsLVneed {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    //修改title
    NSMutableAttributedString *alertControllerStr = [[NSMutableAttributedString alloc] initWithString:@"填写信息不全"];
    [alertControllerStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorFromHexCode:@"#333333"] range:NSMakeRange(0, 6)];
    [alertControllerStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, 6)];
    [alertController setValue:alertControllerStr forKey:@"attributedTitle"];
    
    //修改message
    NSString *str = [NSString stringWithFormat:@"不满足意向等级【%@】需求",_djString];
    NSMutableAttributedString *alertControllerMessageStr = [[NSMutableAttributedString alloc] initWithString:str];
    [alertControllerMessageStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorFromHexCode:@"#333333"] range:NSMakeRange(0, str.length)];
    [alertControllerMessageStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:NSMakeRange(0, str.length)];
    [alertController setValue:alertControllerMessageStr forKey:@"attributedMessage"];
    
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"继续填写" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        
    }];
    
    [cancelAction setValue:[UIColor colorFromHexCode:@"#333333"] forKey:@"titleTextColor"];
    
    UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"我要保存" style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
        PerfectInformationViewController *pvc = [[PerfectInformationViewController alloc] init];
        pvc.khIntention = _djString;
        pvc.isTransaction = self.isTransaction;
        [self.navigationController pushViewController:pvc animated:YES];
        [pvc setPerfectInformationVCBook:^(NSString *remarkString, NSString *type){
            _isActual = type;
            if (_isflg == NO) {
                NSString *str = nil;
                if ([type isEqualToString:@"1"]) {
                    str = nil;
                }else {
                    str = _djNumber;
                }
                [self postAddCustomerApiIntentionLevelRemark:remarkString intentionLevel:str];
            }else {
                NSString *str = nil;
                if ([type isEqualToString:@"1"]) {
                    str = nil;
                }else {
                    str = _djNumber;
                }
                [self postEditCustomerApiIntentionLevelRemark:remarkString intentionLevel:str];
            }
        }];
    }];
    [otherAction setValue:[UIColor colorFromHexCode:@"#F87242"] forKey:@"titleTextColor"];
    
    [alertController addAction:cancelAction];
    [alertController addAction:otherAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)creatNormalProcess {

    if (_nameString.length == 0 || _nameString.length > 30) {
        [self showToast:@"客户姓名需大于0小于30个字符"];
        return;
    }
    if (_xjNumber.length == 0) {
        [self showToast:@"星级未选择"];
        return;
    }
    if (_sexString.length == 0) {
        [self showToast:@"性别未填写"];
        return;
    }
    if (_phonSting.length == 0) {
        [self showToast:@"客户电话未填写"];
        return;
    }
    if (_djString.length == 0) {
        [self showToast:@"意向等级未选择"];
        return;
    }
//    if (_lyStrting.length == 0) {
//        [self showToast:@"客户性质未选择"];
//        return;
//    }
//    if (_ztString.length == 0) {
//        [self showToast:@"客户状态未选择"];
//        return;
//    }
    
    if (_informedWay.length == 0) {
        [self showToast:@"客户获知途径未选择"];
        return;
    }
    
    if ([_informedwayEnumName isEqualToString:@"外部推荐"] ||[_informedwayEnumName isEqualToString:@"全员营销"] ) {
        if (_recommendedCategoryEnumName.length == 0) {
            [self showToast:@"推荐人类别未选择"];
            return;
        }
    }
    
    if ([_informedwayEnumName isEqualToString:@"外部推荐"] ||[_informedwayEnumName isEqualToString:@"全员营销"] ) {
        if (_recommendedName.length == 0) {
            [self showToast:@"推荐人姓名未填写"];
            return;
        }
    }
    
    if ([_informedwayEnumName isEqualToString:@"外部推荐"] ||[_informedwayEnumName isEqualToString:@"全员营销"] ) {
        if (_recommendedMobile.length == 0) {
            [self showToast:@"推荐人手机号未填写"];
            return;
        }
    }
    
    if (_scjcFSSting.length == 0) {
        [self showToast:@"首次接触方式未选择"];
        return;
    }
    
    if (_scjcSJSting.length == 0) {
        [self showToast:@"首次接触时间未选择"];
        return;
    }
    
    if (self.isflg && self.getCustomerDetail.ftContactWay1) {
        if (_scGTSting.length == 0 || self.scGTString1 == 0) {
            [self showToast:@"沟通内容未输入"];
            return;
        }
    }else {
        if (_scGTSting.length == 0) {
            [self showToast:@"沟通内容未输入"];
            return;
        }
    }
    
    if ([_djString isEqualToString:@"A"]) {//A 意向等级必填项
        if (_zyjdString.length == 0) {
            [self showToast:@"置业动机未选择"];
            return;
        }
        
        if (_gzzdArr.count == 0) {
            [self showToast:@"关注重点未选择"];
            return;
        }
        
        if (_xqmjString.length == 0) {
            [self showToast:@"需求面积未选择"];
            return;
        }
        
        if (_fkfsString.length == 0) {
            [self showToast:@"付款方式未选择"];
            return;
        }
        
//        if (_housingArr.count == 0) {
//            [self showToast:@"意向房源未选择"];
//            return;
//        }
        
        if (_rqServicesNameArr.count == 0) {
            [self showToast:@"生活服务未选择"];
            return;
        }
        
        if (_khJZQSting.length == 0) {
            [self showToast:@"居住区未选择"];
            return;
        }
       
        if (_khGZQSting.length == 0) {
            [self showToast:@"工作区未选择"];
            return;
        }
        
        if (_khCszyString.length == 0) {
            [self showToast:@"从事行业未选择"];
            return;
        }
      
    }
    
    if (_isflg == NO) {
        [self postAddCustomerApiIntentionLevelRemark:nil intentionLevel:_djNumber];
    }else {
        [self postEditCustomerApiIntentionLevelRemark:nil intentionLevel:_djNumber];
    }
}

#pragma mark - 新增Api调用
- (void)postAddCustomerApiIntentionLevelRemark:(NSString *)intentionLevelRemark intentionLevel:(NSString *)intentionLevel {
    [self showHud:@"正在提交数据....." inTime:5];
    AddCustomerApi *api = [[AddCustomerApi alloc] initWithCustomerName:_nameString
                                                          customerStar:_xjNumber
                                                           customerSex:_sexNumber
                                                         customerPhone:_phonSting
                                                        intentionLevel:intentionLevel
                                                        customerOrigin:_lyNumber
                                                        customerStatus:_ztNumber
                                                        rqTheirMotives:_zyjdNumber
                                                             rqFocusId:_gzzdNumber
                                                          rqDemandArea:_xqmjNumber
                                                      rqPaymentMethod:_fkfsNumber
                                                          rqServicesId:_fwNumber
                                                              roomList:_housingArrId
                                                          ftContactWay:_scjcNumber
                                                         ftContactTime:_scjcSJSting
                                                      ftContactContent:_scGTSting
                                                 peResidenceProvinceId:_peResidenceProvinceId
                                                     peResidenceCityId:_peResidenceCityId
                                                     peResidenceAreaId:_peResidenceAreaId
                                                peWorkaroundProvinceId:_peWorkaroundProvinceId
                                                    peWorkaroundCityId:_peWorkaroundCityId
                                                    peWorkaroundAreaId:_peWorkaroundAreaId
                                                              industry:_khCszyIdString
                                                  intentionLevelRemark:intentionLevelRemark
                                                           informedWay:_informedWay
                                                   recommendedCategory:_recommendedCategoryEnum
                                                       recommendedName:_recommendedName
                                                     recommendedMobile:_recommendedMobile
                                                       recommendedUnit:_recommendedUnit];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        AddCustomerApi *result = (AddCustomerApi *)request;
        if (result.isSuccess) {
            //            AddCustomer *get = result.resultData;
            [self.navigationController popViewControllerAnimated:YES];
        } else {
//            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}

#pragma mark - 修改Api调用
- (void)postEditCustomerApiIntentionLevelRemark:(NSString *)intentionLevelRemark intentionLevel:(NSString *)intentionLevel {
    [self showHud:@"正在提交数据....." inTime:5];
    EditCustomerApi *api = [[EditCustomerApi alloc] initWithCustomerId:_customerId
                                                          customerName:_nameString
                                                          customerStar:_xjNumber
                                                           customerSex:_sexNumber
                                                         customerPhone:_phonSting
                                                        intentionLevel:intentionLevel
                                                        customerOrigin:_lyNumber
                                                        customerStatus:_ztNumber
                                                        rqTheirMotives:_zyjdNumber
                                                             rqFocusId:_gzzdNumber
                                                          rqDemandArea:_xqmjNumber
                                                       rqPaymentMethod:_fkfsNumber
                                                          rqServicesId:_fwNumber
                                                              roomList:_housingArrId
                                                          ftContactWay:_scjcNumber
                                                         ftContactTime:_scjcSJSting
                                                      ftContactContent:_scGTSting
                                                 peResidenceProvinceId:_peResidenceProvinceId
                                                     peResidenceCityId:_peResidenceCityId
                                                     peResidenceAreaId:_peResidenceAreaId
                                                peWorkaroundProvinceId:_peWorkaroundProvinceId
                                                    peWorkaroundCityId:_peWorkaroundCityId
                                                    peWorkaroundAreaId:_peWorkaroundAreaId
                                                              industry:_khCszyIdString
                                                  intentionLevelRemark:intentionLevelRemark
                                                           informedWay:_informedWay
                                                   recommendedCategory:_recommendedCategoryEnum
                                                       recommendedName:_recommendedName
                                                     recommendedMobile:_recommendedMobile
                                                       recommendedUnit:_recommendedUnit newNote:self.scGTString1];
    
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
        EditCustomerApi *result = (EditCustomerApi *)request;
        if (result.isSuccess) {
            [self hideHud];
            if ([_isTransaction isEqualToString:@"1"]) {
                if ([_transactionType isEqualToString:@"1"]) {
                    GetSubscribeDetail *get = [[GetSubscribeDetail alloc] init];
                    AddSubscriptionViewController *nvc = [[AddSubscriptionViewController alloc] init];
                    nvc.isSFNew = @"0";
                    nvc.customerId = self.customerId;
                    nvc.getSubscribeDetail = get;
                    nvc.isTransaction = _isTransaction;
                    [self.navigationController pushViewController:nvc animated:YES];
                }else if ([_transactionType isEqualToString:@"2"]) {
                    AddNewSignViewController *nvc = [[AddNewSignViewController alloc] init];
                    nvc.customerId = self.customerId;
                    nvc.isAdd = YES;
                    nvc.paymentMethod = _fkfsString;
                    nvc.floorType = @"0";
                    nvc.busReturnType = @"0";
                    nvc.konString = @"0";
                    NSMutableArray *arr = [[NSMutableArray alloc] init];
                    nvc.jJRDataArr = arr;
                    nvc.isTransaction = _isTransaction;
                    [self.navigationController pushViewController:nvc animated:YES];
                }
                
            }else {
                if (_newCustomersBlock) {
                    _newCustomersBlock();
                }
                
                [self.navigationController popViewControllerAnimated:YES];
            }
        } else {
//            [self showToast:result.resultData.errorMsg];
            NSUserDefaults *userdf = [NSUserDefaults standardUserDefaults];
            NSString *projectCode = [userdf objectForKey:@"projectCode"];
            if ([NSString isStringEmpty2:projectCode] == NO) {
                [self showToast:result.resultData.errorMsg];
            }
            
            /*
             提示语：账号权限发生变动，请重新登录
             code随机18位唯一码：108E65843mYuwqb01X
             //YUplf0wyU5vPVssLSG 对应的异地登录退出登录
             */
            if ([result.resultData.errorCode isEqualToString:@"YUplf0wyU5vPVssLSG"] || [result.resultData.errorCode isEqualToString:@"108E65843mYuwqb01X"]) {
                NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
                NSDictionary *dictionary = [defs dictionaryRepresentation];
                for(NSString *key in [dictionary allKeys]){
                    if ([key isEqualToString:@"DeviceToken123"] ||
                        [key isEqualToString:@"loginText"] ||
                        [key isEqualToString:@"provinceCityDistrict"]) {
                    }else {
                        [defs removeObjectForKey:key];
                        [defs synchronize];
                    }
                }
                UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:result.resultData.errorMsg preferredStyle:UIAlertControllerStyleAlert];
                UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
                    [appInstance showLogin];
                }];
                [alertController addAction:cancelAction];
                [self presentViewController:alertController animated:YES completion:nil];
            }
        }
        [self hideHud];
    } failure:^(YTKBaseRequest *request) {
        [self showToast:@"连接服务器失败，请检查网络！"];
        [self hideHud];
    }];
}


#pragma mark - 删除
- (void)pickerViewRemoveFromSuperview {
    _sHQSeleView.hidden = YES;
}

#pragma 点击阴影视图消失
- (void)tapClick:(UITapGestureRecognizer *)tap {
    _sHQSeleView.hidden = YES;
}

#pragma mark -
- (void)sHQPickerShowUI {
    
    _sHQSeleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, EMM_HEIGHT)];
    _sHQSeleView.backgroundColor = [[UIColor colorFromHexCode:@"#1A1A1A"] colorWithAlphaComponent:0.5];
    _sHQSeleView.userInteractionEnabled = YES;
    //    [self.view addSubview:_sHQSeleView];
    [[UIApplication sharedApplication].keyWindow addSubview:_sHQSeleView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    [_sHQSeleView addGestureRecognizer:tap];
    
    _sHQPickerView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height-300, [UIScreen mainScreen].bounds.size.width, 300)];
    _sHQPickerView.backgroundColor = [UIColor whiteColor];
    UIView *v1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 1)];
    v1.backgroundColor = [UIColor lightGrayColor];
    [_sHQPickerView addSubview:v1];
    
    _pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 30, [UIScreen mainScreen].bounds.size.width, 270)];
    _pickerView.delegate = self;
    _pickerView.backgroundColor = [UIColor whiteColor];
    [_sHQPickerView addSubview:_pickerView];
    
    UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, EMM_WIDTH, 54)];
    title.textAlignment = NSTextAlignmentCenter;
    title.text = @"选择地址";
    title.font = [UIFont systemFontOfSize:16];
    [_sHQPickerView addSubview:title];
    
    UIButton *qxBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    qxBtn.frame = CGRectMake(15, 7.5, 50, 40);
    [qxBtn setTitleColor:[UIColor colorFromHexCode:@"#1A1A1A"] forState:UIControlStateNormal];
    [qxBtn setTitle:@"取消" forState:UIControlStateNormal];
    [qxBtn addTarget:self action:@selector(qxBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_sHQPickerView addSubview:qxBtn];
    
    UIButton *wcBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    wcBtn.frame = CGRectMake(EMM_WIDTH - 65, 7.4, 50, 40);
    [wcBtn setTitleColor:[UIColor colorFromHexCode:@"#1A1A1A"] forState:UIControlStateNormal];
    [wcBtn setTitle:@"完成" forState:UIControlStateNormal];
    [wcBtn addTarget:self action:@selector(wcBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [_sHQPickerView addSubview:wcBtn];
    
    UIView *hxView = [[UIView alloc] initWithFrame:CGRectMake(0, 54, EMM_WIDTH, 1)];
    hxView.backgroundColor = [UIColor colorFromHexCode:@"#CCCCCC"];
    [_sHQPickerView addSubview:hxView];
    
    
    
    _sHQSeleView.hidden = YES;
    [_sHQSeleView addSubview:_sHQPickerView];
}

#pragma mark - 取消
- (void)qxBtnClick:(UIButton *)btn {
    [self pickerViewRemoveFromSuperview];
}


#pragma mark - 完成
- (void)wcBtnClick:(UIButton *)btn {
    
    if ([_qbSsqString isEqualToString:@"1"]) {
        //        _khHJDZSting = [NSString stringWithFormat:@"%@-%@-%@",sName,sqName,xName];
    }else if ([_qbSsqString isEqualToString:@"2"]) {
        _khJZQSting = [NSString stringWithFormat:@"%@-%@-%@",sName,sqName,xName];
        _peResidenceProvinceId = sId;
        _peResidenceCityId = sqId;
        _peResidenceAreaId = xId;
    }else if ([_qbSsqString isEqualToString:@"3"]) {
        _khGZQSting =  [NSString stringWithFormat:@"%@-%@-%@",sName,sqName,xName];
        _peWorkaroundProvinceId = sId;
        _peWorkaroundCityId = sqId;
        _peWorkaroundAreaId = xId;
    }
    [self pickerViewRemoveFromSuperview];
    [_customersTableView reloadData];
}


#pragma mark - UIPicker Delegate
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 3;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    if (component == 0) {
        return self.levelOneArr.count;
    } else if (component == 1) {
        NSString *provinceId = self.levelOneArr[self.levelOneSelect][@"provinceId"];
        NSDictionary *dict = self.levelTwoArr[self.levelOneSelect];
        return [dict[provinceId] count];
        
    }
    
    NSString *provinceId = self.levelOneArr[self.levelOneSelect][@"provinceId"];
    NSDictionary *dict = self.levelTwoArr[self.levelOneSelect];
    
    NSString *cityID = dict[provinceId][self.levelTwoSelect][@"cityId"];
    for (NSDictionary *subDict in self.levelThrArr) {
        if ([subDict[cityID] count]) {
            return [subDict[cityID] count];
        }
    }
    return 0;
}


- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {
    UILabel *label = [[UILabel alloc]init];
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:16.0f];
    
    if (component == 0) {
        label.text = self.levelOneArr[row][@"province"];
        sName = self.levelOneArr[row][@"province"];
        NSLog(@"%@",sName);
        sId = self.levelOneArr[row][@"provinceId"];
    }else if (component == 1) {
        NSString *provinceId = self.levelOneArr[self.levelOneSelect][@"provinceId"];
        NSDictionary *dict = self.levelTwoArr[self.levelOneSelect];
        label.text = [NSString stringWithFormat:@"%@",dict[provinceId][row][@"city"]];
        sqName = [NSString stringWithFormat:@"%@",dict[provinceId][row][@"city"]];
        sqId = [NSString stringWithFormat:@"%@",dict[provinceId][row][@"cityId"]];
    }else {
        NSString *provinceId = self.levelOneArr[self.levelOneSelect][@"provinceId"];
        NSDictionary *dict = self.levelTwoArr[self.levelOneSelect];
        
        NSString *cityID = dict[provinceId][self.levelTwoSelect][@"cityId"];
        
        for (NSDictionary *subDict in self.levelThrArr) {
            if ([subDict[cityID] count]) {
                label.text = [NSString stringWithFormat:@"%@",subDict[cityID][row][@"district"]];
                xName =  [NSString stringWithFormat:@"%@",subDict[cityID][row][@"district"]];
                xId =  [NSString stringWithFormat:@"%@",subDict[cityID][row][@"districtId"]];
            }
        }
    }
    
    return label;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component {
    CGFloat pickViewWidth = EMM_WIDTH/3;
    
    return pickViewWidth;
}


- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    if (component == 0) {
        [pickerView selectRow:0 inComponent:1 animated:NO];
        [pickerView selectRow:0 inComponent:2 animated:NO];
        
        self.levelOneSelect = row;
        self.levelTwoSelect = 0;
        
        [pickerView reloadComponent:1];
        [pickerView reloadComponent:2];
        
        NSLog(@"省：%@",self.levelOneArr[row][@"province"]);
        sName = self.levelOneArr[row][@"province"];
        sId = self.levelOneArr[row][@"provinceId"];
        
        NSString *provinceId = self.levelOneArr[self.levelOneSelect][@"provinceId"];
        NSDictionary *dict = self.levelTwoArr[self.levelOneSelect];
        NSLog(@"市：%@",dict[provinceId][0][@"city"]);
        sqName = dict[provinceId][0][@"city"];
        sqId = dict[provinceId][0][@"cityId"];
        NSString *cityID = dict[provinceId][self.levelTwoSelect][@"cityId"];
        for (NSDictionary *subDict in self.levelThrArr) {
            if ([subDict[cityID] count]) {
                NSLog(@"区：%@",subDict[cityID][0][@"district"]);
                xName = subDict[cityID][0][@"district"];
                xId = subDict[cityID][0][@"districtId"];
            }
        }
    }else if (component == 1) {
        [pickerView selectRow:0 inComponent:2 animated:NO];
        
        self.levelTwoSelect = row;
        self.levelThrSelect = 0;
        
        [pickerView reloadComponent:2];
        
        NSString *provinceId = self.levelOneArr[self.levelOneSelect][@"provinceId"];
        NSDictionary *dict = self.levelTwoArr[self.levelOneSelect];
        NSLog(@"市：%@",dict[provinceId][row][@"city"]);
        sqName = dict[provinceId][row][@"city"];
        sqId = dict[provinceId][row][@"cityId"];
        
        NSString *cityID = dict[provinceId][self.levelTwoSelect][@"cityId"];
        for (NSDictionary *subDict in self.levelThrArr) {
            if ([subDict[cityID] count]) {
                NSLog(@"区：%@",subDict[cityID][0][@"district"]);
                xName = subDict[cityID][0][@"district"];
                xId = subDict[cityID][0][@"districtId"];
            }
        }
    }else {
        self.levelThrSelect = row;
        
        NSString *provinceId = self.levelOneArr[self.levelOneSelect][@"provinceId"];
        NSDictionary *dict = self.levelTwoArr[self.levelOneSelect];
        
        NSString *cityID = dict[provinceId][self.levelTwoSelect][@"cityId"];
        
        for (NSDictionary *subDict in self.levelThrArr) {
            if ([subDict[cityID] count]) {
                NSLog(@"区：%@",subDict[cityID][row][@"district"]);
                xName = subDict[cityID][row][@"district"];
                xId = subDict[cityID][row][@"districtId"];
            }
        }
    }
    NSLog(@"省：%@,%@",sName,sId);
    NSLog(@"市：%@,%@",sqName,sqId);
    NSLog(@"区：%@,%@",xName,xId);
}

@end
